Merge PDF documents in C# using Aspose.PDF - NullReferenceException with DocuSign PDFs

I have a PDF created by DocuSign, that I would like to merge into a larger PDF. However, whenever I attempt to do this, I receive a NullReferenceException

I attempted to remove the signature but still received the null exception.

The merge process I’m using works with all other PDFs, but for whatever reason it cannot deal with the DocuSign PDF.

@mpayne

Could you please share your sample source PDF document along with the code snippet. We will test the scenario in our environment and address it accordingly.

@asad.ali No problem, thanks!

Aspose.Pdf.Document mergeDoc = new Aspose.Pdf.Document();
Aspose.Pdf.Document docA = new Aspose.Pdf.Document("docusign.pdf");
mergeDoc.Pages.Add(docA.Pages);
// add other docs to merge
mergeDoc.Save("merge.pdf");

I add other docs to the “mergeDoc”, but the error should throw with just that.

docusign.pdf (275.5 KB)

@mpayne

We tested the scenario in our environment while using Aspose.PDF for .NET 21.1 and your code snippet. We did not notice any issue. Please check the attached output PDF generated at our end.

merged.pdf (278.6 KB)

Would you please try using the latest version of the API and let us know in case you still face any issue.

@asad.ali Thanks for your help. I am embarrassed to say I thought I had “Just My Code” debugging enabled (but did not), and didn’t even notice the NULL exceptions could be stepped through without issue; so there must just be some normal exception handling occurring in the library.

Thanks again for your help and sorry for the confusion.

@mpayne

It is good to know that your issue has been resolved. Please keep using our API and feel free to create a new topic in case you need further assistance.