Since July 2024, we call Aspose.Pdf.Repair before calling Aspose.Pdf.Convert when converting PDF to PDF/A, to prevent stack overflow when an input PDF file is corrupt. This resolved the issue we reported in this ticket:
The stack overflow issue is indeed resolved. However, our customers now report that PDF output files are sometimes corrupt. Images are missing in the output PDF and Acrobat reports that the PDF is damaged.
Attached is an example of a PDF in PDF/A-1a format that will be damaged by Aspose.Pdf.Repair:
284283-test.A1a.pdf (90.8 KB)
We can use this code to convert the file to PDF/UA-1:
string sTestA1aPdf = Path.GetFullPath(@"284283-test.A1a.pdf");
string sTestUA1Pdf = Path.GetFullPath(@"284283-test.UA1.pdf");
// Save without using Repair method
if (File.Exists(sTestUA1Pdf)) File.Delete(sTestUA1Pdf);
using (Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(sTestA1aPdf))
using (MemoryStream ms = new MemoryStream())
{
pdfDocument.Convert(ms, Aspose.Pdf.PdfFormat.PDF_UA_1,
Aspose.Pdf.ConvertErrorAction.Delete);
pdfDocument.Save(sTestUA1Pdf);
}
The resulting output file is as expected: 284283-test.UA1.pdf (91.2 KB)
However, when we use Repair, the output file is corrupted:
string sTestA1aPdf = Path.GetFullPath(@"284283-test.A1a.pdf");
string sTestUA1repair = Path.GetFullPath(@"284283-test.repair-used.UA1.pdf");
// Open same input file, use Repair and then save
if (File.Exists(sTestUA1repair)) File.Delete(sTestUA1repair);
using (Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(sTestA1aPdf))
using (MemoryStream ms = new MemoryStream())
{
pdfDocument.Repair(new Aspose.Pdf.Document.RepairOptions {
RestoreIndirectObjectGenerations = true });
pdfDocument.Convert(ms, Aspose.Pdf.PdfFormat.PDF_UA_1,
Aspose.Pdf.ConvertErrorAction.Delete);
pdfDocument.Save(sTestUA1repair);
}
The output file is smaller because the logo image is not present:
284283-test.repair-used.UA1.pdf (64.8 KB)
Acrobat displays an error when opening the file: image.png (5.2 KB)
An error exists on this page. Acrobat may not display the page correctly. Please contact
the person who created the PDF document to correct the problem.
We currently use Aspose.PDF for .NET version 24.6. I could also reproduce the problem using latest Aspose.PDF for .NET version 24.10.