Skip to main content
A newer version of this page is available. .

How to: Extract Pages from a Document

  • 2 minutes to read

Important

You require 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 shows how to extract the first page from a document into a separate PDF document.

To accomplish this task:

  • Use the PdfDocumentProcessor.LoadDocument method to load a source document;
  • Call the PdfDocumentProcessor.CreateEmptyDocument method to create an empty target document;
  • Add the first page from the source document to the target document.

    Access the target document using the PdfDocumentProcessor.Document property. The PdfDocument.Pages property provides access to the pages’ collection. Add pages to the collection using the Add method. To access the first page in the page collection of a source document, use the zero page index.

    When you add a page from another document, all page content, including bookmarks referring to this page, is copied to the resulting document.

using DevExpress.Pdf;

namespace ExtractFirstPage {
    class Program {
        static void Main(string[] args) {

            using (PdfDocumentProcessor source = new PdfDocumentProcessor()) {
                source.LoadDocument("..\\..\\Document.pdf");
                using (PdfDocumentProcessor target = new PdfDocumentProcessor()) {
                    target.CreateEmptyDocument("..\\..\\ExtractedFirstPage.pdf");
                    target.Document.Pages.Add(source.Document.Pages[0]);
                }
            }
        }
    }
}
See Also