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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: WinForms |
Control: PDF |
Published Date: April 30, 2011 |
Last Revised Date: May 3, 2019
Tags: pdf, pages, remove

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.

 

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