Java POI 生成PDF文档,很给力!
来源:互联网 发布:金牛期货软件怎么样 编辑:程序博客网 时间:2024/05/16 00:52
package poi.itext;
import java.io.FileOutputStream;
import java.io.IOException;
import java.awt.Color;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import com.lowagie.text.pdf.BaseFont;
/**
* 创建Pdf文档
* @author Administrator
*
*/
public class HelloPdf
{
public static void main(String[] args)throws Exception
{
BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Font FontChinese = new Font(bfChinese, 12, Font.NORMAL);
// 第一步,创建document对象
Rectangle rectPageSize = new Rectangle(PageSize.A4);
//下面代码设置页面横置
//rectPageSize = rectPageSize.rotate();
//创建document对象并指定边距
Document doc = new Document(rectPageSize,50,50,50,50);
Document document = new Document();
try
{
// 第二步,将Document实例和文件输出流用PdfWriter类绑定在一起
//从而完成向Document写,即写入PDF文档
PdfWriter.getInstance(document,new FileOutputStream("src/poi/itext/HelloWorld.pdf"));
//第3步,打开文档
document.open();
//第3步,向文档添加文字. 文档由段组成
document.add(new Paragraph("Hello World"));
Paragraph par = new Paragraph("世界你好",FontChinese);
document.add(par);
PdfPTable table = new PdfPTable(3);
for(int i=0;i<12;i++)
{
if (i == 0)
{
PdfPCell cell = new PdfPCell();
cell.setColspan(3);
cell.setBackgroundColor(new Color(180,180,180));
cell.addElement(new Paragraph("表格头" , FontChinese));
table.addCell(cell);
}
else
{
PdfPCell cell = new PdfPCell();
cell.addElement(new Paragraph("表格内容" , FontChinese));
table.addCell(cell);
}
}
document.add(table);
}
catch (DocumentException de)
{
System.err.println(de.getMessage());
}
catch (IOException ioe)
{
System.err.println(ioe.getMessage());
}
//关闭document
document.close();
System.out.println("生成HelloPdf成功!");
}
}
- Java POI 生成PDF文档,很给力!
- java生成pdf文档
- java生成pdf文档
- Java POI 生成Word文档
- Java POI 生成Word文档
- 使用java生成pdf文档
- 使用Java生成Pdf文档
- 使用Java生成Pdf文档
- 使用Java生成Pdf文档
- java生成PDF格式文档
- Java 生成 EXCEL POI文档说明
- Java 生成 EXCEL POI文档说明
- JAVA POI excel文档解析与生成
- 利用Java Apache POI 生成Word文档
- 利用Java Apache POI 生成Word文档
- 利用Java Apache POI 生成Word文档
- 利用Java Apache POI 生成Word文档
- 利用Java Apache POI 生成Word文档
- hdu1879继续畅通工程
- 打印1~100中不能被7整除又不包括7的数
- 用ClientScript类动态添加脚本
- javascript事件key,mouse中的区别(个人理解+参考w3school)
- Intellij IDEA13 创建多模块Maven项目
- Java POI 生成PDF文档,很给力!
- 学习堆排序
- Android-支付宝快捷支付
- springMVC框架下JQuery传递并解析Json数据
- 输入两个数,求最小公倍数和最大公约数
- UNITY3D载入TXT文件进行显示
- iOS:UITableView 使用(一)--基本使用
- 部署、收回和删除解决方案----STSADM和PowerShell
- ArcEngine创建内存FeatureClass