How to: Delete Pages from a Document

  • 2 minutes to read
IMPORTANT

You need a license to the DevExpress Office File API or DevExpress Universal Subscription to use these examples in production code. Refer to the DevExpress Subscription page for pricing information.

This example illustrates how to use the PDF Document API component for deleting pages from a document.

In this example, the PdfDocumentProcessor.DeletePage method is called 55 times to delete each odd numbered page in the TextDelete document (contains 109 pages), starting from the last odd numbered page.

The result is saved to the Deleted document, which contains only even pages, by calling the PdfDocumentProcessor.SaveDocument method.

using DevExpress.Pdf;
// ...
    class Program {
        static void Main(string[] args) {
            using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor()) {
                pdfDocumentProcessor.LoadDocument("..\\..\\docs\\TextDelete.pdf");
                for (int i = pdfDocumentProcessor.Document.Pages.Count / 2; i >= 0; i--)
                    pdfDocumentProcessor.DeletePage(i * 2 + 1);
                pdfDocumentProcessor.SaveDocument("..\\..\\docs\\Deleted.pdf");
            }
        }
    }
See Also