Error message "Wrong format of page's content" when saving merged PDFs

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.

I was going to attach the base and supporting documents I have been testing with, but I can’t find anywhere to attach files…

@smunn

Apologies for the delayed response. Please attach your files in .zip format using the upload button in screenshot.
image.png (8.5 KB)

SampleDocs.zip (7.0 MB)

Thanks, attached you will find a zip file with 2 files:

BaseDoc.pdf - this is a well formed PDF that our system generates with Aspose
SupportingDoc.pdf - this is a customer uploaded PDF that we know is bad (fails to open in Acrobat, but will open in Edge)

When we merge SupportingDoc.pdf into BaseDoc.pdf using the code I submitted above, it makes it through all the tests and then fails when the merged document is saved. We are trying to figure out a way to determine the SupportingDoc.pdf is bad before we get that far. And if there is a way to correct it.

@smunn

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): PDFNET-56308

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.

Thank you. It might be helpful to me if you are able to describe the nature of the issue and what is in fact wrong with the “bad” PDF I attached.

@smunn

It needs investigation to determine what actually is the issue with these PDFs and why API is unable to detect in the first place. Therefore, a ticket has been generated in our issue management system. We will look into its details and as soon as we are done with the investigation, we will update you via this forum thread. Please spare us some time.

We are sorry for the inconvenience.