0
iText Java 라이브러리를 사용하여 주어진 HTML 템플릿에서 A5 페이지 크기 PDF 문서를 생성하고 싶습니다.Java iText를 사용하여 HTML에서 A5 PDF 문서 생성
PDF를 생성하는 데 성공했지만 A5 페이지가 아닌 A4 페이지 하나에 공백 A5 페이지가 나타납니다 (the output document 참조). 내가 도대체 뭘 잘못하고있는 겁니까?
샘플 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();
}
}
감사합니다. 시도해 보겠습니다. 그러나 API 문서는 이에 대해 명확하지 않습니다 ("클래스는 패키지 전용이었습니다"라는 말 제외). http://api.itextpdf.com/itext/com /itextpdf/text/pdf/PdfDocument.html – Petr
API 문서가 아닌이 책을 참조하려고합니다. –
솔루션이 실제로 작동했습니다. PdfAWriter (http : //api.itextpdf. co.kr/pdfa /)에 따르면 생성자는 PdfDocument를 사용합니다 ... – Petr