iText官方教程

來源:互聯網
上載者:User

如果要匯出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();    }}

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.