Mar 13, 2006

iText にチャレンジ

iText とは

iText は Java から PDF を扱うライブラリ。 ライセンスは MPLLGPL のデュアルライセンス。

iText
http://www.lowagie.com/iText/
API Document
http://itextdocs.lowagie.com/docs/
Tutorial: iText by Example
http://itext.sourceforge.net/tutorial/

サンプルコード

とりあえずお決まりの Hello World。

package jp.in_vitro.codelets.itext;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;

public class Codelet {

    public Codelet() {
        super();
    }

    public static void main(final String[] args) throws FileNotFoundException,
            DocumentException {
        Codelet me = new Codelet();
        me.execute();
    }

    protected void execute() throws FileNotFoundException, DocumentException {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream("c:\\HelloWorld.pdf"));
        document.open();
        document.add(new Paragraph("Hello World"));
        document.close();
    }
}
[作成された PDF]

TrackBack ping me at
http://www.in-vitro.jp/blog/index.cgi/Library/20060313_01.trackback
Post a comment

writeback message: Ready to post a comment.