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:

  • load a source document using the PdfDocumentProcessor.LoadDocument method;
  • create a target document with no pages using one of the PdfDocumentProcessor.CreateEmptyDocument overloaded methods;
  • add the first page from the source document to the target document.

    The target document can be accessed using the PdfDocumentProcessor.Document property. To access a collection of pages within the target document, use the PdfDocument.Pages property. Then, you’re able to 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.

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