Hi, i’m trying to convert a PNG/JPEG/GIF to PDF in PDF/A-1a format. Unfortunately the test to validate the PDF Format 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 the validation 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)