Fel
Fel

Reputation: 4828

Adding pages to PDF/A file with PDFBox without losing PDF/A validity

I'm developing a Java application that has to process a folder with PDF/A files, adding a page with some information to each of them using Apache's PDFBox library. The problem is that the output PDF file after adding the information is not PDF/A anymore. This is a validation test from the website: https://www.pdf-online.com/osa/validate.aspx:

Validation output

And this is the relevant part of the code that I use to generate the PDF file:

  String pdfFileName = this.baseFolder+this.extendedPDFFileName;

  File file = new File(pdfFileName); 

  PDDocument pdfFile = PDDocument.load(file);

  PDPage pag = new PDPage();

  // As a test, simply adding a page makes the PDF unvalid as PDF/A
  pdfFile.addPage(pag);

  pdfFile.save(file);

  pdfFile.close();

What could I do to keep the PDF/A format validity? Thanks in advance,

Upvotes: 1

Views: 578

Answers (2)

Fel
Fel

Reputation: 4828

As Tilman Hausherr suggested, the problem has been solved by adding a PDResources object to the new page, like this:

pag.setResources(new PDResources());

Now I'm having troubles with the embedded fonts, but this is another question :)

Many thanks!

Upvotes: 1

C4mps
C4mps

Reputation: 188

You create a normal PDF in your code, you should create a valid PDF/A from the start. Here's a link: https://pdfbox.apache.org/1.8/cookbook/pdfacreation.html

Upvotes: 0

Related Questions