NullReferenceException convert PDF to PDFA

test.pdf (129.9 KB)

Converting the attached PDF to PDFA(PDF_A_1A) throws a NullRefereneException.
Aspose Version : 19.1.0
Language : C#

@FabianOW

Thanks for contacting support.

We have tested the scenario in our environment using Aspose.PDF for .NET 19.2 and following code snippet. We were unable to replicate the issue which you have mentioned.

Document pdfDocument = new Document(dataDir + "test.pdf");
// Convert 
pdfDocument.Convert(dataDir + "ExamplePDF.log", PdfFormat.PDF_A_1A, ConvertErrorAction.Delete, ConvertTransparencyAction.Mask);
// Save output document
pdfDocument.Save(dataDir + "1-Src_pdfab.pdf");

1-Src_pdfab.pdf (3.3 MB)

For your kind reference, an output PDF file has also been attached. Would you please try using latest version of the API and in case you still face any issue, please feel free to let us know.

Thanks for your quick answer.
After looking into the code again, i found out, that the error only appears with OptimizeResources and LinkDuplcateStream = true.

doucment.OptimizeResources(new Aspose.Pdf.Document.OptimizationOptions()
            {
                LinkDuplcateStreams = true,
                RemoveUnusedObjects = true,
                RemoveUnusedStreams = true,
                CompressImages = true,
                ImageQuality = 70
            });

I also tried Version 19.2, same error.

@FabianOW

Thanks for writing back.

Would you please try saving document once before optimizing it using following code snippet. In case you still face any issue, please feel free to let us know.

Document pdfDocument = new Document(dataDir + "test.pdf");
// Convert 
pdfDocument.Convert(dataDir + "ExamplePDF.log", PdfFormat.PDF_A_1A, ConvertErrorAction.Delete, ConvertTransparencyAction.Mask);
// Save output document
pdfDocument.Save(dataDir + "1-Src_pdfab.pdf");
pdfDocument = new Document(dataDir + "1-Src_pdfab.pdf");
Optimization.OptimizationOptions options = new Optimization.OptimizationOptions();
options.LinkDuplcateStreams = true;
options.RemoveUnusedObjects = true;
options.RemoveUnusedStreams = true;
options.ImageCompressionOptions.CompressImages = true;
options.ImageCompressionOptions.ImageQuality = 70;
pdfDocument.OptimizeResources(options);
pdfDocument.Save(dataDir + "optimized.19.2.pdf");

optimized.19.2.pdf (2.7 MB)