)
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

Best practices to append, merge, and import pages from the PDF

Platform: WinForms |
Control: PDF |
Published Date: April 25, 2019 |
Last Revised Date: April 25, 2019
Tags: pdf, c#, merge, append, vb.net

Syncfusion Essential PDF is a .NET PDF library used to create, read and edit PDF documents. Using this library, you can merge, append and import pages from PDF documents.

Best practises to append, merge and import pages from PDF document

While perform append, merge and import pages from PDF document, by default EnableMemoryOptimization property set to true. Effective from Essential Studio product version 17.1.0.32, we have changed this behaviour and set EnableMemoryOptimization property to false by default.

Please refer the below details which explains about enable and disabling of EnableMemoryOptimization property while perform append, merge and import pages from PDF document.

EnableMemoryOptmization=true

If you need to optimize the memory, you can set EnableMemoryOptimization to true. It will optimize the memory only but different in time occurs based on the document size. While setting this property to true, we have cloned each and every object from existing PDF document. So, you can close the existing document before saving of new PDF document.

Please refer the below code example for more details,

Appending PDF document:

//Loads the PDF document 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
 
//Creates a new PDF document 
PdfDocument document = new PdfDocument();
 
//Set EnableMemoryOptimization to true
document.EnableMemoryOptimization = true;
 
//Appending the document with source document 
document.Append(loadedDocument);
 
//Close the loaded document
loadedDocument.Close(true);
 
//Save the document
document.Save("Sample.pdf");
 
//Close the new document 
document.Close(true);

 

Merging PDF document:

//Loads the PDF document 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
 
//Creates a new PDF document 
PdfDocument document = new PdfDocument();
 
//Set EnableMemoryOptimization to true
document.EnableMemoryOptimization = true;
 
//Appending the document with source document 
PdfDocumentBase.Merge(document, loadedDocument);
 
//Close the loaded document
loadedDocument.Close(true);
 
 
//Save the document
document.Save("Sample.pdf");
 
//Close the new document 
document.Close(true);

 

Importing pages from PDF document:

//Loads the PDF document 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
 
//Creates a new PDF document 
PdfDocument document = new PdfDocument();
 
//Set EnableMemoryOptimization to true
document.EnableMemoryOptimization = true;
 
//Imports the pages from loaded document
document.ImportPageRange(loadedDocument, 0, loadedDocument.Pages.Count - 1);
 
//Close the loaded document
loadedDocument.Close(true);
 
//Save the document
document.Save("Sample.pdf");
 
//Close the new document 
document.Close(true);

 

EnableMemoryOptimization=false

If you need to improve the performance, you can disable the EnableMemoryOptimization or by default it set to false. Performance will be increased but memory optimization will be low compared to enabling of this property. If it is set to false, needs to close the existing PDF document only after saving of new PDF document.

Please refer the below code example for more details,

Appending PDF document:

//Loads the PDF document 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
 
//Creates a new PDF document 
PdfDocument document = new PdfDocument();
 
//Appending the document with source document 
document.Append(loadedDocument);
 
//Save the document
document.Save("Sample.pdf");
 
//Close the loaded document
loadedDocument.Close(true);
 
//Close the new document 
document.Close(true);

 

Merging PDF document:

//Loads the PDF document 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
 
//Creates a new PDF document 
PdfDocument document = new PdfDocument();
 
//Appending the document with source document 
PdfDocumentBase.Merge(document, loadedDocument);
 
//Save the document
document.Save("Sample.pdf");
 
//Close the loaded document
loadedDocument.Close(true);
 
//Close the new document 
document.Close(true);

 

Import pages from PDF document:

//Loads the PDF document 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
 
//Creates a new PDF document 
PdfDocument document = new PdfDocument();
 
//Imports the pages from loaded document
document.ImportPageRange(loadedDocument, 0, loadedDocument.Pages.Count - 1);
 
//Save the document
document.Save("Sample.pdf");
 
//Close the loaded document
loadedDocument.Close(true);
 
//Close the new document 
document.Close(true);

 

Take a moment to peruse the documentation, where you can find the options like merging multiple documents from disk and stream, importing pages from multiple documents and split PDF document with code example.

Refer here to explore the rich set of Syncfusion Essential PDF features.

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

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