Remove pages from PDFs in C#
Nutrient .NET SDK (formerly GdPicture.NET) enables you to remove pages from PDF files and multipage TIFF files.
Download sampleTo remove the second-to-last page of a PDF file, use the following code:
Register the SDK license before running SDK operations. For setup details, refer to the getting started with .NET SDK guide.
using GdPicture14;
LicenseManager license = new LicenseManager();license.RegisterKEY("");using GdPicturePDF gdpicturePDF = new GdPicturePDF();gdpicturePDF.LoadFromFile(@"input.pdf");// Remove second-to-last page.gdpicturePDF.DeletePage(gdpicturePDF.GetPageCount() - 1);gdpicturePDF.SaveToFile(@"output.pdf");Register the SDK license before running SDK operations. For setup details, refer to the getting started with .NET SDK guide.
Imports GdPicture14
Dim license As LicenseManager = New LicenseManager()license.RegisterKEY("")Using gdpicturePDF As GdPicturePDF = New GdPicturePDF() gdpicturePDF.LoadFromFile("input.pdf") ' Remove second-to-last page. gdpicturePDF.DeletePage(gdpicturePDF.GetPageCount() - 1) gdpicturePDF.SaveToFile("output.pdf")End UsingUsed methods
To remove the first page of a TIFF file, use the following code:
GdPictureImaging gdpictureImage = new GdPictureImaging();int imageID = gdpictureImage.TiffCreateMultiPageFromFile(@"multipage-tiff.tif");// Remove first page.gdpictureImage.TiffDeletePage(imageID, 1);gdpictureImage.TiffSaveMultiPageToFile(imageID, @"output.tif", TiffCompression.TiffCompressionAUTO);gdpictureImage.ReleaseGdPictureImage(imageID);Using gdpictureImage As GdPictureImaging = New GdPictureImaging() Dim imageID As Integer = gdpictureImage.TiffCreateMultiPageFromFile("multipage-tiff.tif") ' Remove first page. gdpictureImage.TiffDeletePage(imageID, 1) gdpictureImage.TiffSaveMultiPageToFile(imageID, "output.tif", TiffCompression.TiffCompressionAUTO) gdpictureImage.ReleaseGdPictureImage(imageID)End UsingRelated topics