This sample shows how to remove pages from your PDF documents.
Use PdfDocument.RemovePage or PdfDocument.RemovePages method to remove pages from a document. You can use a page index, an instance of PdfPage class or a collection of page indexes or PdfPage objects with these methods.
using System.Diagnostics; namespace BitMiracle.Docotic.Pdf.Samples { public static class RemovePages { public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. PdfDocument pdf = new PdfDocument(); PdfPage firstPage = pdf.Pages[0]; firstPage.Canvas.DrawString(10, 50, "Main page"); //add page to the end and then delete it pdf.AddPage(); pdf.RemovePage(pdf.PageCount - 1); //another way to delete page PdfPage pageToDelete = pdf.AddPage(); pdf.RemovePage(pageToDelete); //we can delete several pages at once pdf.InsertPage(0); pdf.InsertPage(1); pdf.RemovePages(new int[] { 0, 1 }); pdf.Save("RemovePages.pdf"); pdf.Dispose(); Process.Start("RemovePages.pdf"); } } }
Imports System.Diagnostics Imports System.IO Imports BitMiracle.Docotic.Pdf Namespace BitMiracle.Docotic.Pdf.Samples Public NotInheritable Class RemovePages Public Shared Sub Main() ' NOTE: ' When used in trial mode, the library imposes some restrictions. ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx ' for more information. Dim pdf As New PdfDocument() Dim firstPage As PdfPage = pdf.Pages(0) firstPage.Canvas.DrawString(10, 50, "Main page") 'add page to the end and then delete it pdf.AddPage() pdf.RemovePage(pdf.PageCount - 1) 'another way to delete page Dim pageToDelete As PdfPage = pdf.AddPage() pdf.RemovePage(pageToDelete) 'we can delete several pages at once pdf.InsertPage(0) pdf.InsertPage(1) pdf.RemovePages(New Integer() {0, 1}) pdf.Save("RemovePages.pdf") pdf.Dispose() Process.Start("RemovePages.pdf") End Sub End Class End Namespace
