0

iText Java ライブラリを使用して、特定の HTML テンプレートから A5 ページ サイズの PDF ドキュメントを生成したいと考えています。

PDF の生成には成功しましたが、A5 ページ 1 ページではなく、A4 ページ (テキスト付き) 1 ページと、それに続く空の A5 ページ (出力ドキュメントを参照) が得られます。私は何を間違っていますか?

サンプル Java コードは次のとおりです。

助けてくれてありがとう。


public final class Main {

    public static void main(String[] args) throws IOException, DocumentException {
        htmlToPdf(new StringReader("<html><head><title>Hello, World!!!</title></head><body style=\"font-family: 'Times New Roman', serif;\"><div>Hello, World!!!</div></body></html>"), new File("Test.pdf"));
    }

    private static void htmlToPdf(final StringReader htmlSource, final File pdfOutput) throws IOException, DocumentException {

        final FileOutputStream pdfOutputStream = new FileOutputStream(pdfOutput);
        final PdfDocument document = new PdfDocument();

        FontFactory.defaultEmbedding = true;

        document.setPageSize(com.itextpdf.text.PageSize.A5);

        final PdfWriter pdfWriter = PdfAWriter.getInstance(document, pdfOutputStream, PdfAConformanceLevel.PDF_A_1B);
        document.addWriter(pdfWriter);
        document.open();

        XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, htmlSource);

        document.close();
        pdfOutputStream.close();
    }
}
4

1 に答える 1

0

PdfDocumentインスタンスではなく、インスタンスを作成していDocumentます! 文書化されているように、このPdfDocumentクラスは内部使用専用です。

于 2013-06-10T08:22:14.147 に答える