Image to PDF/A-1a is not working in Java

Hi, i’m trying to convert a PNG/JPEG/GIF to PDF in PDF/A-1a format. Unfortunately the test failed:

    @Test
    void testImageToPdfA1a() throws IOException {
        try(ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
            Resource inputDocument = new ClassPathResource("sampleInput.png");

            Image image = Image.load(inputDocument.getInputStream());

            PdfOptions pdfOptions = new PdfOptions();
            PdfCoreOptions pdfCoreOptions = new PdfCoreOptions();
            pdfCoreOptions.setPdfCompliance(PdfComplianceVersion.PdfA1a);
            pdfOptions.setPdfCoreOptions(pdfCoreOptions);

            image.save(outputStream, pdfOptions);

            InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());

            assertThat(new Document(inputStream).validate(outputStream, PdfFormat.PDF_A_1A)).isTrue();
        }
    }

Does anyone knows what i’m doing wrong ? For PDF/A-1b it is working:

    @Test
    void testImageToPdfA1b() throws IOException {
        try(ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
            Resource inputDocument = new ClassPathResource("sampleInput.png");

            Image image = Image.load(inputDocument.getInputStream());

            PdfOptions pdfOptions = new PdfOptions();
            PdfCoreOptions pdfCoreOptions = new PdfCoreOptions();
            pdfCoreOptions.setPdfCompliance(PdfComplianceVersion.PdfA1b);
            pdfOptions.setPdfCoreOptions(pdfCoreOptions);

            image.save(outputStream, pdfOptions);

            InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());

            assertThat(new Document(inputStream).validate(outputStream, PdfFormat.PDF_A_1B)).isTrue();
        }
    }

I’m using JDK 17 or 21 and
Maven: com.aspose:aspose-imaging:jdk16:23.10 (aspose-imaging-23.10-jdk16.jar)

Hello, @KevinK!
We appreciate your interest in Aspose.Imaging.
Could you send me the error you faced? Or stack trace? Or source png file?

Best regards

attached the PNG. There is no error but the validation fails so i get no PDF/A-1a format out.

ConvertDocumentToPDFServiceTest.sampleInput.png.zip (30,7 KB)

@KevinK
Thank you, let me take a look at this.

I have tested your examples. It produced correct PDF files in both cases, and Adobe PDF Reader can open them. The reason for the error in validating I can not explain, I think you should relay this question to the Aspose.PDF team.
Let me know if I can do more for you.
Best regards

Hello @evgeniy.sidenko,
first of all, thank you for your help. But here a few questions:

  • How can you verify, that the outcome document is in the a PDF/A-1a format ?
  • How can i reach the Aspose.PDF Team ?

If i upload the document to PDF/A validator | PDFen.com then i get

CHECK FAILED
THE DOCUMENT DOES NOT CONFORM TO THE PDF/A-1A STANDARD.

Thank you!

@KevinK
I open the output PDF file with Adobe Acrobat Reader and it says that it is PDF/A-1a and only for reading.
Ok, we are going to check it out with PDF/A validator | PDFen.com
You can write this question to this forum in the “Aspose.PDF Product Family” branch.

created a new thread here:

1 Like

@KevinK
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): IMAGINGJAVA-8611

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like