java操作pdf

iText是一个开源的PDF工具,小巧而又便捷。

官方网站是:http://www.lowagie.com/iText/官方的解释:iText is a library that allows you to generate PDF files . the fly最新版本为:2.1.5下载地址是:http://nchc.dl.sourceforge.net/sourceforge/itext/iText-2.1.5.jar

package com.test;import java.io.FileOutputStream; import java.io.IOException; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.PdfWriter; public class HelloWorld { public static void main(String[] args) { System.out.println(“Hello World”); //第一步:创建一个document对象。 Document document = new Document(); try { // 第二步: // 创建一个PdfWriter实例, // 将文件输出流指向一个文件。PdfWriter.getInstance(document,new FileOutputStream(“d://HelloWorld.pdf”)); // 第三步:打开文档。 document.open(); // 第四步:在文档中增加一个段落。 document.add(new Paragraph(“Hello World”+”,”+”Hello iText”+”,”+”Hello”)); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // 第五步:关闭文档。 document.close(); // 检验程序是否正常运行到这里。 System.out.println(“文档生成完毕”); } }

一只小狗在沙漠中旅行,找到了电线杆,结果还是憋死了,

java操作pdf

相关文章:

你感兴趣的文章:

标签云: