JAVA操作PDF文件

近些天项目中需要生成PDF报表,网上查了下java生成PDF文件的方式,大概有两种,一种是利用jacob调用EXCEL另存为PDF文件,另一张是

用第三方开源库iText.jar直接生成PDF文件,这两种我都试了下,结合项目的需求,感觉还是使用iText生成PDF报表更为自由。以下是示例代码,记录一下

iText如何简单的生成PDF文件及表格。


                        String path = UatsResources.getAppPath()+uats.getItem()+"/test-report.pdf";
			com.lowagie.text.Document document = new com.lowagie.text.Document();
			PdfWriter.getInstance(document, new FileOutputStream(path));
			document.open();
			
			BaseFont 	style 	= BaseFont.createFont("STSongStd-Light","UniGB-UCS2-H", false);
	                Font 		chinese = new Font(style, 8, Font.BOLD,Color.BLACK);
	        
			PdfPTable table = new PdfPTable(10);
			table.addCell(new PdfPCell(new Phrase("编号",chinese)));
			table.addCell(new PdfPCell(new Phrase("应用名称",chinese)));
			table.addCell(new PdfPCell(new Phrase("文件类型",chinese)));
			table.addCell(new PdfPCell(new Phrase("应用版本",chinese)));
			table.addCell(new PdfPCell(new Phrase("安装情况",chinese)));
			table.addCell(new PdfPCell(new Phrase("应用启动",chinese)));
			table.addCell(new PdfPCell(new Phrase("应用退出",chinese)));
			table.addCell(new PdfPCell(new Phrase("应用运行",chinese)));
			table.addCell(new PdfPCell(new Phrase("卸载情况",chinese)));
			table.addCell(new PdfPCell(new Phrase("测试类型",chinese)));
			table.addCell(new PdfPCell(new Phrase("安全检查",chinese)));
			table.addCell(new PdfPCell(new Phrase("启动时间",chinese)));
			table.addCell(new PdfPCell(new Phrase("CPU占用",chinese)));
			table.addCell(new PdfPCell(new Phrase("内存占用",chinese)));
			table.addCell(new PdfPCell(new Phrase("测试时间",chinese)));
			table.addCell(new PdfPCell(new Phrase("测试人员",chinese)));
			document.add(table);
			document.close();
			


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值