Articles in this section
Category / Section

How to remove pages from an existing PDF file using C# and VB.NET?

6 mins read

The Syncfusion Essential PDF is a feature-rich and high-performance .NET PDF library used to create, read, and edit PDF documents programmatically without Adobe dependencies. This library also offers functionality to merge, split, stamp, forms, compress, and secure PDF files.

Using this library, you can remove pages from an existing PDF document in C# and VB.NET. This sample uses the following PDF document.

PDF document

Steps to remove the pages form existing PDF document programmatically in C#:

  1. Create a new C# console application project. Create a console application in Visual Studio
  2. Install the Syncfusion.Pdf.WinForms NuGet package as reference to your .NET Framework application from NuGet.org. Refer NuGet to the project
  3. Include the following namespaces in Program.cs file.

C#

using Syncfusion.Pdf.Parsing;

 

VB.NET

Imports Syncfusion.Pdf.Parsing

 

  1. Include the following code snippet in main method of Program.cs file, to remove pages from an existing PDF document using the RemoveAt method of PdfLoadedPageCollection.

C#

//Load an existing PDF document into PdfLoadedDocument
PdfLoadedDocument document = new PdfLoadedDocument("SourceTemplate.pdf");
 
//Remove the second page
document.Pages.RemoveAt(1);           
 
//Save the PDF document
document.Save("Sample.pdf");
 
//Close the instance of PdfLoadedDocument
document.Close(true);

 

VB.NET

'Load an existing PDF document into PdfLoadedDocument
Dim document As PdfLoadedDocument = New PdfLoadedDocument("SourceTemplate.pdf")
 
'Remove the second page
document.Pages.RemoveAt(1)
 
'Save the PDF document
document.Save("Sample.pdf")
 
'Close the instance of PdfLoadedDocument
document.Close(True)

 

  1. You can also remove pages from a PDF document using the Remove method of PdfLoadedPageCollection.

C#

//Remove the second page
document.Pages.Remove(document.Pages[1]);

 

VB.NET

'Remove the second page
document.Pages.Remove(document.Pages(1))

 

A complete work sample to remove pages from an existing PDF document can be downloaded from Remove-Pages.zip.

By executing the program, you will get the PDF document as follows.

Remove pages from PDF document

Take a moment to peruse the documentation, where you will find other options like adding new page in a PDF document, importing pages from existing PDF document, re-arranging and changing page numbers in existing PDF document, rotating PDF page, splitting a PDF document into individual pages.

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

An online sample link for different page settings.

Note:

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.

 


Conclusion
I hope you enjoyed learning on how to remove pages from an existing PDF file using C# and VB.NET.
You can refer to our WinForms PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms PDF example to understand how to create and manipulate data.For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!
Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied