Java实现PDF的生成(使用IText)
- 基本步骤
参考地址:1、新建document对象
2、建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中
3、打开文档
4、向文档中添加内容
5、关闭文档
http://blog.csdn.net/yi2419808933/article/details/52469241
http://blog.csdn.net/justinytsoft/article/details/53320225?locationNum=4&fps=1
http://www.cnblogs.com/dengjiali/articles/2521301.html
http://blog.csdn.net/jixiangrurui/article/details/41042925
- Java生成pdf方案总结
一种思路:Freemarker+Flying sauser+Itext 整合生成PDF1. Jasper Report生成pdf:设计思路是先生成模板,然后得到数据,最后将两者整合得到结果。但是Jasper Report的问题在于,其生成模板的方式过于复杂,即使有IDE的帮助,我们还是需要对其中的众多规则有所了解才行,否则就会给调试带来极大的麻烦。
2. openoffice生成pdf:openoffice是开源软件且能在windows和linux平台下运行。
3. itext + flying saucer生成pdf:itext和flying saucer都是免费开源的,且与平台无关,结合css和velocity技术,可以很好的实现。
http://blog.csdn.net/lewee0215/article/details/44238889?locationNum=16
https://blog.csdn.net/jimmy609/article/details/12748053
- PDF操作中的一些类
文本的对象:块(Chunk)、短句(Phrase)、段落(Paragraph)
https://my.oschina.net/smellok/blog/73727
- Java程序实现Word文档转为pdf以及出现的问题解决(使用jacob)
http://blog.csdn.net/u013238430/article/details/52943075
http://blog.csdn.net/ilovejavas/article/details/17501899
注意:Word转PDF可以使用OpenOffice
- 添加水印文字
http://blog.sina.com.cn/s/blog_d5af62a70102vhrv.html
http://www.cnblogs.com/tankqiu/p/4412898.html
/** * 加水印(字符串) * @param inputFile 需要加水印的PDF路径 * @param outputFile 输出生成PDF的路径 * @param waterMarkName 水印字符 */ public static void stringWaterMark(String inputFile, String waterMarkName) { try { String[] spe = PDFStyle.separatePath(inputFile); String outputFile = spe[0] + "_WM." + spe[1]; PdfReader reader = new PdfReader(inputFile); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputFile)); int total = reader.getNumberOfPages() + 1; PdfContentByte under; //给每一页加水印 for (int i = 1; i < total; i++) { Rectangle rectangle = stamper.getReader().getPageSizeWithRotation(i); float x = rectangle.getWidth()/2; float y = rectangle.getHeight()/2-5; under = stamper.getUnderContent(i); under.beginText(); under.setFontAndSize(PDFStyle.getBaseFont(), 35); under.setTextMatrix(200, 120); under.setColorFill(new Color(238, 209, 212)); under.showTextAligned(Element.ALIGN_CENTER, waterMarkName, x, y, 50); // 添加水印文字 under.endText(); under.stroke(); } stamper.close(); } catch (Exception e) { e.printStackTrace(); } } /** * 分割路径 * @param path * @return 返回分割后的路径 */ public static String[] separatePath(String path){ if(StringUtils.isBlank(path)){ return null; } String[] sep = path.split("\\."); return new String[]{sep[0],sep[1]}; }
- 合并PDF
http://blog.csdn.net/qq_32566703/article/details/70112058
http://blog.csdn.net/MissEel/article/details/75220571
//合并PDF public static void pdfMerge(Document document , PdfWriter pdfWriter){ try { PdfReader pdfReader; //附加信息PDF pdfReader = new PdfReader("E:\\附加信息.pdf"); PdfContentByte pdfContentByte = pdfWriter.getDirectContent(); int totalPages = pdfReader.getNumberOfPages(); int pageOfCurrentReaderPDF = 0; while (pageOfCurrentReaderPDF < totalPages) { //创建新的一页 document.newPage(); pageOfCurrentReaderPDF++; PdfImportedPage page = pdfWriter.getImportedPage(pdfReader, pageOfCurrentReaderPDF); pdfContentByte.addTemplate(page, 0, 0); } } catch (IOException e) { e.printStackTrace(); } }
- iText和flying saucer结合生成pdf的技术(这个还没去实现/测试)
https://blog.csdn.net/yelongshang1/article/details/51098242
http://gaojunwei.iteye.com/blog/1996749
https://blog.csdn.net/xxj_jing/article/details/70888607
https://blog.csdn.net/cuiyaonan2000/article/details/42459259
https://blog.csdn.net/mhouwei62/article/details/51394804
注意:Itext中的Table与PdfTable
http://www.open-open.com/doc/view/c4331fe8a1084315890ee17df8f96da1
https://blog.csdn.net/feng27156/article/details/16879069
上一篇: 【Java】使用iText生成PDF文件
下一篇: 详细介绍ASP.NET中的C#基础知识
推荐阅读
-
使用DevExpress的PdfViewer实现PDF打开、预览、另存为、打印(附源码下载)
-
最小生成树的java实现
-
使用rst2pdf实现将sphinx生成PDF
-
使用java实现四则运算的生成 (罗彬 梁汉烽)
-
【工具篇】在.Net中实现HTML生成图片或PDF的几种方式
-
Python使用win32com模块实现数据库表结构自动生成word表格的方法
-
PHP使用imagick读取PDF生成png缩略图的两种方法
-
详解java中的深拷贝和浅拷贝(clone()方法的重写、使用序列化实现真正的深拷贝)
-
使用php实现下载生成某链接快捷方式的解决方法
-
ThinkPHP5&5.1实现验证码的生成、使用及点击刷新功能示例