Using Aspose.Pdf 23.12 (most recent version at the time of this writing. We have a situation where one of our clients is uploading some PDFs with a non-standard structure or something and we are trying to figure out how to detect them before they are merged with PDFs our system generates. We know their PDFs have an issue because they will not open in Acrobat either (throws an error), but they are not complete garbage because they will open and are visible in MS Edge.
The problem is the bad PDFs may be instantiated in a Aspose.Pdf document without any errors, and even saved again without any errors. We have tried the Validate method, but they pass this test. We are also able to add their pages collection to the pages collection of our base PDF. It’s when we save the merged PDF that we get the error “Wrong format of page’s content”.
Here is a distilled snipped of code:
var baseFormat = baseDocument.PdfFormat; << baseDocument is a well formed PDF doc
if (supportingDocsToAdd.Any())
{
foreach (var supDoc in supportingDocsToAdd)
{
var tmpDoc = new Aspose.Pdf.Document(supportingDocWithPath);
var tmpDocFormat = tmpDoc.PdfFormat;
var options = new PdfFormatConversionOptions(baseFormat);
if (!tmpDoc.Validate(options)) << this never fails
{
//Error handling - never gets hit
}
if(tmpDocFormat != baseFormat)
{
tmpDoc.Convert(options);
}
var tmpPath = Path.Combine(tempPath, Guid.NewGuid().ToString() + ".pdf");
//Try to Save to validate << this never fails
tmpDoc.Save(tmpPath);
baseDocument.Pages.Add(tmpDoc.Pages); << this never fails
}
}
documents.FirstOrDefault(s => s.IsBaseDocument).Document.Save(path); << Failure here
Any help is appreciated. If we can test the supporting document before it gets merged, that would be ideal, but all our attempts have failed. It doesn’t fail until the full merged document is saved.