Skip to main content

PdfDocument Class

A document contained in a PDF file.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Pdf.v23.2.Core.dll

NuGet Package: DevExpress.Pdf.Core

Declaration

public class PdfDocument

The following members return PdfDocument objects:

Remarks

The PdfDocument class contains members that allow you to perform the following operations with a PDF document:

Organize PDF Pages

Use the PdfDocument.Pages properties to organize pages in a PDF file. Refer to the following article for more information: Organize Pages in PDF Documents

The code sample below copies a page from one PDF document to another.

View Example: How to copy a page from one document to another

using DevExpress.Pdf;

using (PdfDocumentProcessor source = new PdfDocumentProcessor())
{
    source.LoadDocument("..\\..\\Document1.pdf");
    using (PdfDocumentProcessor target = new PdfDocumentProcessor())
    {
        target.LoadDocument("..\\..\\Document2.pdf");
        target.Document.Pages.Insert(3, source.Document.Pages[0]);
        target.SaveDocument("..\\..\\Result.pdf");
    }
}

Obtain Document Information

The following properties indicate the document information:

Obtain Applied Permissions

The following properties indicate what permissions are applied to the document:

Permission Property
Printer Permissions AllowPrinting
AllowHighQualityPrinting
Data Extraction Permissions AllowDataExtraction
AllowAccessibility
Modification Restrictions AllowModifying
AllowDocumentAssembling
Interactivity Permissions AllowAnnotationsAndFormsModifying
AllowFormsFilling

Specify Viewer Preferences

The ViewerPreferences property allows you to access the view preferences.

The code sample below specifies the document’s view preferences:

using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor())
{
    pdfDocumentProcessor.LoadDocument("Documents//Invoice.pdf");
    PdfDocument document = pdfDocumentProcessor.Document;

    PdfViewerPreferences preferences = new PdfViewerPreferences();
    preferences.DisplayDocTitle = true;
    preferences.HideMenubar = true;
    preferences.FitWindow = true;
    preferences.PrintNumCopies = 3;

    document.ViewerPreferences = preferences;
}

Use the PageLayout property to specify the layout of the opened document.

Set Document Metadata

Call the SetMetadata to embed XMP metadata in the document. Refer to the following article for more information: Embed XMP Metadata in a PDF Document

The code sample below loads metadata from a file and embeds it in the document:

using DevExpress.Pdf;
using DevExpress.Pdf.Xmp;
//...

using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor())
{
    pdfDocumentProcessor.LoadDocument("Documents//Invoice.pdf");
    PdfDocument document = pdfDocumentProcessor.Document;
    XmpDocument metadata = new XmpDocument();
    using (FileStream xmlStream = new FileStream("Documents//metadata.xml", FileMode.Open, FileAccess.Read))
    {
        metadata = XmpDocument.FromStream(xmlStream);
        document.SetMetadata(metadata);
    }

    pdfDocumentProcessor.SaveDocument("Invoice_Upd.pdf");
}

Use Document Facade

Use the PdfDocumentProcessor.DocumentFacade property to retrieve a document facade - a set of methods used to perform various operations on PDF document without access to its inner structure. The PdfDocumentFacade instance allows you to organize annotations, change form fields, and remove page content. Refer to the following articles for more information:

Inheritance

Object
PdfDocument
See Also