iText サンプルプログラム

目次

空白ページが1ページあるだけのPDFを作成する


try {
    //PDFドキュメントを作成
    Document document = new Document();
    FileOutputStream stream = new FileOutputStream("hogehoge.pdf");

    PdfWriter writer = PdfWriter.getInstance(document, stream);
    document.open();
    writer.setPageEmpty(false);
    document.newPage();
    document.close();
    stream.close();
} catch (IOException e) {
    e.printStackTrace();
} catch (DocumentException e) {
    e.printStackTrace();
}