Back to Devexpress

PdfDocument Class

officefileapi-devexpress-dot-pdf-02086893.md

latest7.7 KB
Original Source

PdfDocument Class

A document contained in a PDF file.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public class PdfDocument :
    IPdfDocument
vb
Public Class PdfDocument
    Implements IPdfDocument

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

csharp
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");
    }
}
vb
Imports DevExpress.Pdf

Using source As New PdfDocumentProcessor()
    source.LoadDocument("..\..\Document1.pdf")
    Using target As New PdfDocumentProcessor()
        target.LoadDocument("..\..\Document2.pdf")
        target.Document.Pages.Insert(3, source.Document.Pages(0))
        target.SaveDocument("..\..\Result.pdf")
    End Using
End Using

Obtain Document Information

The following properties indicate the document information:

Obtain Applied Permissions

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

PermissionProperty
Printer PermissionsAllowPrinting
AllowHighQualityPrinting
Data Extraction PermissionsAllowDataExtraction
AllowAccessibility
Modification RestrictionsAllowModifying
AllowDocumentAssembling
Interactivity PermissionsAllowAnnotationsAndFormsModifying
AllowFormsFilling

Specify Viewer Preferences

The ViewerPreferences property allows you to access the view preferences.

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

csharp
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;
}
vb
Using pdfDocumentProcessor As New PdfDocumentProcessor()
  pdfDocumentProcessor.LoadDocument("Documents//Invoice.pdf")
  Dim document As PdfDocument = pdfDocumentProcessor.Document

  Dim preferences As New PdfViewerPreferences()
  preferences.DisplayDocTitle = True
  preferences.HideMenubar = True
  preferences.FitWindow = True
  preferences.PrintNumCopies = 3

  document.ViewerPreferences = preferences
End Using

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:

csharp
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");
}
vb
Imports DevExpress.Pdf
Imports DevExpress.Pdf.Xmp
'...

Using pdfDocumentProcessor As New PdfDocumentProcessor()
    pdfDocumentProcessor.LoadDocument("Documents//Invoice.pdf")
    Dim document As PdfDocument = pdfDocumentProcessor.Document
    Dim metadata As New XmpDocument()
    Using xmlStream As New FileStream("Documents//metadata.xml", FileMode.Open, FileAccess.Read)
        metadata = XmpDocument.FromStream(xmlStream)
        document.SetMetadata(metadata)
    End Using

    pdfDocumentProcessor.SaveDocument("Invoice_Upd.pdf")
End Using

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

PdfDocument Members

DevExpress.Pdf Namespace