Remove Pages from PDFs in C#
PSPDFKit GdPicture.NET Library allows you to remove pages from PDF files and multipage TIFF files.
To remove the second-to-last page of a PDF file, use the following code:
using GdPicturePDF gdpicturePDF = new GdPicturePDF(); gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf"); // Remove second-to-last page. gdpicturePDF.DeletePage(gdpicturePDF.GetPageCount() - 1); gdpicturePDF.SaveToFile(@"C:\temp\output.pdf");
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF() gdpicturePDF.LoadFromFile("C:\temp\source.pdf") ' Remove second-to-last page. gdpicturePDF.DeletePage(gdpicturePDF.GetPageCount() - 1) gdpicturePDF.SaveToFile("C:\temp\output.pdf") End Using
Used Methods
To remove the first page of a TIFF file, use the following code:
GdPictureImaging gdpictureImage = new GdPictureImaging(); int imageID = gdpictureImage.TiffCreateMultiPageFromFile(@"C:\temp\source.tif"); // Remove first page. gdpictureImage.TiffDeletePage(imageID, 1); gdpictureImage.TiffSaveMultiPageToFile(imageID, @"C:\temp\output.tif", TiffCompression.TiffCompressionAUTO); gdpictureImage.ReleaseGdPictureImage(imageID);
Using gdpictureImage As GdPictureImaging = New GdPictureImaging() Dim imageID As Integer = gdpictureImage.TiffCreateMultiPageFromFile("C:\temp\source.tif") ' Remove first page. gdpictureImage.TiffDeletePage(imageID, 1) gdpictureImage.TiffSaveMultiPageToFile(imageID, "C:\temp\output.tif", TiffCompression.TiffCompressionAUTO) gdpictureImage.ReleaseGdPictureImage(imageID) End Using