HTML to PDF/A2 : missing page numbers

Hello!

I convert HTML-files to PDF/A and I add page numbers this way before the conversion:

	private void insertPageNumbers(Document document) {
		int pages = 0;
		try {
			pages = document.getPageCount();
		} catch (Exception e) {
		}

		if (pages > 1) {
			DocumentBuilder builder = new DocumentBuilder(document);
			builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);

			builder.getFont().setName("Arial");
			builder.getFont().setSize(10);

			builder.insertField("PAGE", "");
			builder.write(" / ");
			builder.insertField("NUMPAGES", "");
			builder.getParagraphFormat().setAlignment(ParagraphAlignment.RIGHT);
		}
	}

This worked fine as long as I converted to PDF_A_1_A. But now, as I convert to PDF_A_2_A, the page numbers are not included in the resulting PDF.
Attached are input HTML and output PDF (PDF_A_1_A and PDF_A_2_A): missingPageNumbers.zip (392.8 KB)

Do you have any ideas why there are no page numbers included in the PDF_A_2_A file?

Kind regards!

@dvtdaten Please try updating field before saving document to PDF. Using the following code the problem is not reproducible:

Document doc = new Document("C:\\Temp\\html5test.htm");
insertPageNumbers(doc);
doc.updateFields();
PdfSaveOptions opt = new PdfSaveOptions();
opt.setCompliance(PdfCompliance.PDF_A_2_A);
doc.save("C:\\Temp\\out.pdf", opt);

Thank you, that fixes the problem.

1 Like