)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to manage memory while merging large PDF documents?

Platform: WinForms |
Control: PDF |
Published Date: April 21, 2015 |
Last Revised Date: April 21, 2015
Tags: pdf, merge

Setting the EnableMemoryOptimization property of the PdfLoadedDocument to true reduces the memory usage when its instance is closed. To achieve this, create a PdfDocument, then import the pages and contents of the loaded documents to the PdfDocument, and dispose the loaded document. Finally, save the PdfDocument’s instance and close the same.

C#

Sample Link:

http://www.syncfusion.com/downloads/support/directtrac/general/MemoryOptimize-1342350512.zip

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Andrew Williams
Jan 09, 2017
I'm getting an "Object reference not set to an instance of an object" exception when I use this method with streams instead of file paths. Everything works until I go to save the document. The code doesn't crash if I take out "loadedDocument.Close(true);".

at Syncfusion.Pdf.Primitives.PdfReferenceHolder.get_Index()
   at Syncfusion.Pdf.Primitives.PdfReferenceHolder.GetObject()
   at Syncfusion.Pdf.Primitives.PdfReferenceHolder.get_Object()
   at Syncfusion.Pdf.Primitives.PdfReferenceHolder.Save(IPdfWriter writer)
   at Syncfusion.Pdf.Primitives.PdfDictionary.SaveItems(IPdfWriter writer)
   at Syncfusion.Pdf.Primitives.PdfDictionary.Save(IPdfWriter writer, Boolean bRaiseEvent)
   at Syncfusion.Pdf.Primitives.PdfDictionary.Save(IPdfWriter writer)
   at Syncfusion.Pdf.Primitives.PdfDictionary.SaveItems(IPdfWriter writer)
   at Syncfusion.Pdf.Primitives.PdfDictionary.Save(IPdfWriter writer, Boolean bRaiseEvent)
   at Syncfusion.Pdf.Primitives.PdfDictionary.Save(IPdfWriter writer)
   at Syncfusion.Pdf.Primitives.PdfDictionary.SaveItems(IPdfWriter writer)
   at Syncfusion.Pdf.Primitives.PdfDictionary.Save(IPdfWriter writer, Boolean bRaiseEvent)
   at Syncfusion.Pdf.Primitives.PdfStream.Save(IPdfWriter writer)
   at Syncfusion.Pdf.IO.PdfCrossTable.DoSaveObject(IPdfPrimitive obj, PdfReference reference, PdfWriter writer)
   at Syncfusion.Pdf.IO.PdfCrossTable.SaveIndirectObject(IPdfPrimitive obj, PdfWriter writer)
   at Syncfusion.Pdf.IO.PdfCrossTable.SaveObjects(PdfWriter writer)
   at Syncfusion.Pdf.IO.PdfCrossTable.Save(PdfWriter writer)
   at Syncfusion.Pdf.Parsing.PdfLoadedDocument.AppendDocument(PdfWriter writer)
   at Syncfusion.Pdf.Parsing.PdfLoadedDocument.Save(Stream stream)
Reply
Andrew Williams
Jan 09, 2017
Figured out what I was doing wrong, make sure you Enable Memory Optimization on the Document as well as the loadedDocuments. I forgot to do the former, which I guess leaves behind some references to the pdfs that are loaded into it.

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon