如果要导出PDF文件,首选当然是iText,从网上也找了些资料,有很多,也有些乱。
自己做了个例子,感觉还是很浅,深入的内容还是研究不透。下载了官方的jar包,本来想看看
里面的Demo,结果只有api文档。资料还真是不好找。
今天发现官方还是有很多例子代码的。
下载地址:http://itextpdf.com/examples/
iText官网: http://itextpdf.com/
在首页下面有个Online resources
下面有个 example code 的链接,点击进入后,发现里面是个很华丽的教程,配备实例代码!
http://itextpdf.com/book/examples.php
这比网上其他人写的博客要权威多了,发现这个好东西,和大家分享一下。
里面有16章,内容相当全,还有演示视频。
这是HelloWord例子,其他自己研究吧:
/*
* This class is part of the book "iText in Action - 2nd Edition"
* written by Bruno Lowagie (ISBN: 9781935182610)
* For more info, go to: http://itextpdf.com/examples/
* This example only works with the AGPL version of iText.
*/
package part1.chapter01;
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
/**
* First iText example: Hello World.
*/
public class HelloWorld {
/** Path to the resulting PDF file. */
public static final String RESULT
= "results/part1/chapter01/hello.pdf";
/**
* Creates a PDF file: hello.pdf
* @param args no arguments needed
*/
public static void main(String[] args)
throws DocumentException, IOException {
new HelloWorld().createPdf(RESULT);
}
/**
* Creates a PDF document.
* @param filename the path to the new PDF document
* @throws DocumentException
* @throws IOException
*/
public void createPdf(String filename)
throws DocumentException, IOException {
// step 1
Document document = new Document();
// step 2
PdfWriter.getInstance(document, new FileOutputStream(filename));
// step 3
document.open();
// step 4
document.add(new Paragraph("Hello World!"));
// step 5
document.close();
}
}
分享到:
相关推荐
iText入门基础教程 绝对详细 手把手教你
iText中文教程,中文教程和实例,不过实例代码没有找到,欢迎有代码的人补充并评论加链接。
涵盖了很多itext的例子,从简单到复杂
iText中文教程 附带例子 导入pdf、xml、rtf......
iText中文教程,itext jar包,itext例子
IText经典入门教程,一步一步的教你配置。入门完全没有问题。
利用iText五步创建一个PDF文件:helloword 。第一步,创建一个iTextSharp.text.Document对象的实例: Document document = new Document(); 第二步,为该Document创建一个 Writer 实例: PdfWriter.getInstance...
iText是著名的开放源码的站点sourceforge一个项目,是用于生成PDF文档的一个java类库。通过iText不仅可以生成PDF或rtf的文档,而且可以将XML、Html文件转化为PDF文件。
itext应用介绍(中文版),基本的应用都有详细的注解,本人搜索了很久才找到,值得拥有!!!1
本人iText高级教程系列所有的源码,方便大家结合博文进行练习。
使用iText生成包含中文,图片,表格的PDF,包括中文文档还有demo源码
iText插件教程
iText是一个能够快速产生PDF文件的java类库。iText的java类对于那些要产生包含文本,表格,图形的只读文档是很有用的。它的类库尤其与java Servlet有很好的给合。使用iText与PDF能够使你正确的控制Servlet的输出。
iText是著名的开放源码的站点sourceforge一个项目,是用于生成PDF文档的一个java类库。通过iText不仅可以生成PDF或rtf的文档,而且可以将XML、Html文件转化为PDF文件。 iText的安装非常方便,下载iText.jar文件后,...