itext A4纸张横向创建PDF
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfWriter;
public class Test{
public static void main(String[] as) throws Exception{
        Test.testRotate();
}
/**
*itext A4纸张横向创建PDF,需要加itext jar报
*http://www.cnblogs.com/qgc88/
*/
 public static  void testRotate(){  
            Document document = new Document(); 
        //横向
            Rectangle pageSize = new Rectangle(PageSize.A4.height(), PageSize.A4.width());
            pageSize.rotate();
            document.setPageSize(pageSize);
            
             // 页码
            Page page = new Page();
            page.setPageFormat("— %d —");
            page.setRelativeY(-10);
            page.setRelativeX(-35);
            PdfPageEventHelper eventPage[] = new PdfPageEventHelper[1];
            eventPage[0] = page;
            
            try {  
            String destPath="E:\\test.pdf";
                PdfWriter writer = PdfWriter.getInstance(document,
                        new FileOutputStream(destPath));
if (eventPage != null) {
                    for (PdfPageEventHelper event : eventPage) {
                        writer.setPageEvent(event);
                    }
                }
                document.open();  
                
                 BaseFont fontChinese = null;
                try {
                    fontChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",
                            BaseFont.NOT_EMBEDDED);// 设置中文字体(支持中文显示)
                } catch (Exception e) {
                    e.printStackTrace();
                }
                String titlec="意见汇总";
                  Font chinese12 = new Font(fontChinese, 12, Font.NORMAL);
                  Font chineseB12 = new Font(fontChinese, 12, Font.BOLD);
                  
                  Font chinese = new Font(fontChinese, 18, Font.BOLD);
                   Paragraph title = new Paragraph(titlec, chinese);
                   title.setAlignment(Element.ALIGN_CENTER);
                   
                document.add(title);
                
              
                Table table = new Table(8);   //8是总的列数,也可以同时指定行数和列数new Table(3,4)
                
                table.setTableFitsPage(true);//防止跨页有段开的边框(填充整页)
                
                table.setWidths(new int[]{5,20,10,10,10,10,5,30}); //每列比例
                table.setWidth(100);//表格站table 100%
                table.setBorder(0);
              
                Cell cell = new Cell();
                cell.setHeader(true);
               // cell.setColspan(8);
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.addElement((new Paragraph("序号\n ", chineseB12))); 
                table.addCell(cell); 
              
                cell = new Cell();
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.addElement((new Paragraph("项目名称\n ", chineseB12))); 
                table.addCell(cell); 
                
                cell = new Cell();
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.addElement((new Paragraph("申报单位\n ", chineseB12))); 
                table.addCell(cell); 
                
                cell = new Cell();
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.addElement((new Paragraph("组别\n ", chineseB12))); 
                table.addCell(cell); 
                
                cell = new Cell();
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.addElement((new Paragraph("计划类型\n ", chineseB12))); 
                table.addCell(cell); 
                
                cell = new Cell();
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.addElement((new Paragraph("资金(万元)\n ", chineseB12))); 
                table.addCell(cell); 
                
                cell = new Cell();
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.addElement((new Paragraph("评分\n ", chineseB12))); 
                table.addCell(cell); 
                
                cell = new Cell();
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.addElement((new Paragraph("专家组意见\n ", chineseB12))); 
                table.addCell(cell); 
            
                table.endHeaders();
             
             
                for (int i = 0; i < 20; i++) {
                Cell   cell1 = new Cell(String.valueOf(i));
                cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
                //max lines ,设置成1防止换行,配合cell宽度,可以实现自动截取
              //  cell1.setMaxLines(1);
                table.addCell(cell1); 
                
                Cell   cell2 = new Cell();
                cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell2.setHorizontalAlignment(Element.ALIGN_LEFT);
                cell2.addElement(new Paragraph("项目测目测目测目测目测试1", chinese12));
                table.addCell(cell2);
                
                Cell   cell3 = new Cell();
                cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell3.setHorizontalAlignment(Element.ALIGN_LEFT);
                cell3.addElement(new Paragraph("项目目测目测测试1", chinese12));
                table.addCell(cell3);
                
                Cell   cell4 = new Cell();
                cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell4.addElement(new Paragraph("http://www.cnblogs.com/qgc88/", chinese12));
                table.addCell(cell4);
                
                Cell   cell5 = new Cell();
                cell5.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell5.setHorizontalAlignment(Element.ALIGN_LEFT);
                cell5.addElement(new Paragraph("科技人才需求", chinese12));
                table.addCell(cell5);
                
                Cell   cell6 = new Cell();
                cell6.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell6.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell6.addElement(new Paragraph("22", chinese12));
                table.addCell(cell6);
                
                Cell   cell7 = new Cell();
                cell7.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell7.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell7.addElement(new Paragraph("100.00", chinese12));
                table.addCell(cell7);
                
                Cell   cell8 = new Cell();
                cell8.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell8.setHorizontalAlignment(Element.ALIGN_LEFT);
                cell8.addElement(new Paragraph("主审家综合意", chinese12));
                table.addCell(cell8);
                          
                }
             
                
                document.add(table);
             
            } catch (DocumentException de) {  
                System.err.println(de.getMessage());  
            } catch (IOException ioe) {  
                System.err.println(ioe.getMessage());  
            }  
            document.close();  
        }  
}
itext A4纸张横向创建PDF的更多相关文章
- 使用iText库创建PDF文件
		
前言 译文连接:http://howtodoinjava.com/apache-commons/create-pdf-files-in-java-itext-tutorial/ 对于excel文件的读 ...
 - itext poi 学习之旅 (1)创建pdf
		
从零开始学习itext 创建pdf 1.用到流进行创建的pdf import java.io.File; import java.io.FileOutputStream; import com.ite ...
 - .net快速创建PDF文档 by c#
		
原文地址:http://www.cnblogs.com/Creator/archive/2010/03/13/1685020.html C#引用IText创建PDF文档 先引用IText 可以从 ...
 - 使用Rotativa在ASP.NET Core MVC中创建PDF
		
在本文中,我们将学习如何使用Rotativa.AspNetCore工具从ASP.NET Core中的视图创建PDF.如果您使用ASP.NET MVC,那么Rotativa工具已经可用,我们可以使用 ...
 - NET Core MVC中创建PDF
		
使用Rotativa在ASP.NET Core MVC中创建PDF 在本文中,我们将学习如何使用Rotativa.AspNetCore工具从ASP.NET Core中的视图创建PDF.如果您使用ASP ...
 - C# /VB.NET 创建PDF项目符号列表和多级编号列表
		
使用项目符号和编号,可以让文档的层次结构更清晰.更有条理,也更容易突出重点.在编辑文档的过程中,我个人也比较偏爱项目标号来标注文章重点信息.在之前的文章中,介绍了如何在Word中来创建项目标号和编号列 ...
 - python从TXT创建PDF文件——reportlab
		
使用reportlab创建PDF文件电子书一般都是txt格式的,某些电子阅读器不能读取txt的文档,如DPT-RP1.因此本文从使用python实现txt到pdf的转换,并且支持生成目录,目录能够生成 ...
 - 01.在Java中如何创建PDF文件
		
1.简介 在这篇快速文章中,我们将重点介绍基于流行的iText和PdfBox库从头开始创建 PDF 文档. 2. Maven 依赖 <dependency> <groupId> ...
 - HTML生成横向的PDF
		
HTML生成PDF请参照:https://www.cnblogs.com/yunfeiyang-88/p/10984740.html 如要生成横向的PDF:在html模板的style标签里面加入@pa ...
 
随机推荐
- Codeforces Round #275(Div. 2)-C. Diverse Permutation
			
http://codeforces.com/contest/483/problem/C C. Diverse Permutation time limit per test 1 second memo ...
 - 题解 CF440A 【Forgotten Episode】
			
博客阅读更好 虽然这道题是紫题,但实际难度应该是橙题吧 首先,看到标签…… 紫题?但题目也太…… 这道题教会我们不要看标签 好了,废话少说,看到楼下许多大佬都用了数组,但我觉得可以不用 为什么? 我也 ...
 - kubernetes添加不了google apt-key
			
转自icepoint的博客 key来源 我的百度云盘 密码:v3wo 下载kube_apt_key.gpg到本地,上传到服务器后执行下面的命令 apt-get update && ap ...
 - JS原型链(一)
			
一.创建对象 // 第一种方式:字面量 var o1 = {name: 'o1'}; var o2 = new Object({name: 'o2'}); // 第二种方式:构造函数 var M = ...
 - 【最短路径树】51nod1443 路径和树
			
并不是什么高端操作并且一些模型会用到 Description 给定一幅无向带权连通图G = (V, E) (这里V是点集,E是边集).从点u开始的最短路径树是这样一幅图G1 = (V, E1),其中E ...
 - verilog behavioral modeling --loop statement
			
1.forever 2.repeat 3.while 4.for The for statement accomplishes the same results as the following ps ...
 - 避免使用aireplay-ng指令时出现AP通道不对的方法
			
本方法搜集网络:具体使用为在调试网卡为监听模式,使用airodump-ng指令扫描wifi后,需要先执行"airmon-ng stop wlan0"指令,然后再进行一系列抓包等操作 ...
 - as eclipse 对比
			
eclipse目录结构 src:存放prj源码 gen:自动生成文件,R类存放资源文件的唯一id android+版本:项目jar包 assets:res存放资源文件,不会被gen生成资源id,同过a ...
 - iphone丢了以后发现关机了怎么办?
			
有好几个办法都可以尝试一下: 1. "ICCID法",但目前这个办法只能寻找苹果iPhone手机,而对于安卓手机,则不能采取相同的方法进行寻找.之所以能采取该方法寻找苹果 iPho ...
 - Builder(构造者)
			
Builder(构造者) <?php class Product { private $name; public function setName($name) { $this->name ...