We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Trying to Merge pdfs, get an NullReferenceException

Hello guys,


I'm trying to Merge pdfs using this documentation "https://help.syncfusion.com/file-formats/pdf/merge-documents#merging-multiple-documents-from-disk-and-stream ", but I got the NullReferenceException (see screenshot). My Question is, How I can merge pdfs?


See also the project zipped for reference.




Attachment: MergingPdfsNotWorking_20230404_170175f2.zip

2 Replies 1 reply marked as answer

IJ Irfana Jaffer Sadhik Syncfusion Team April 5, 2023 10:54 AM UTC

We suggest opening the PDF document using streams instead of strings. we provide support to open an existing document from the stream by using PdfLoadedDocument class in the ASP.NET Core Platform. You can refer to the following documentation in ASP.NET core platforms for further details.

https://help.syncfusion.com/file-formats/pdf/merge-documents?cs-save-lang=1&cs-lang=csharp


Modified code:

PdfDocument finalDoc = new PdfDocument();


            FileStream stream1 = new FileStream(PathConstants.DocumentMerge1, FileMode.Open, FileAccess.Read);

            FileStream stream2 = new FileStream(PathConstants.DocumentMerge2, FileMode.Open, FileAccess.Read);

            //Creates a PDF stream for merging.

            Stream[] streams = { stream1, stream2 };



Try this on your end and let us know the result


Marked as answer

LC Luis Campuzano April 5, 2023 12:22 PM UTC

It works this way.

Thanks.


Loader.
Live Chat Icon For mobile
Up arrow icon