iText官方教程
如果要導(dǎo)出PDF文件,首選當(dāng)然是iText,從網(wǎng)上也找了些資料,有很多,也有些亂。
自己做了個(gè)例子,感覺還是很淺,深入的內(nèi)容還是研究不透。下載了官方的jar包,本來想看看
里面的Demo,結(jié)果只有api文檔。資料還真是不好找。
今天發(fā)現(xiàn)官方還是有很多例子代碼的。
下載地址:http://itextpdf.com/examples/
iText官網(wǎng): http://itextpdf.com/
在首頁下面有個(gè)Online resources
下面有個(gè) example code 的鏈接,點(diǎn)擊進(jìn)入后,發(fā)現(xiàn)里面是個(gè)很華麗的教程,配備實(shí)例代碼!
http://itextpdf.com/book/examples.php
這比網(wǎng)上其他人寫的博客要權(quán)威多了,發(fā)現(xiàn)這個(gè)好東西,和大家分享一下。
里面有16章,內(nèi)容相當(dāng)全,還有演示視頻。
這是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 1Document document = new Document();// step 2PdfWriter.getInstance(document, new FileOutputStream(filename));// step 3document.open();// step 4document.add(new Paragraph("Hello World!"));// step 5document.close();} }總結(jié)
- 上一篇: 机械臂——DH参数
- 下一篇: 自动寻路之 --AStar算法