Skip to main content
A newer version of this page is available. .
All docs
V21.1
.NET Framework 4.5.2+

PdfDocumentFacade Class

Exposes a set of methods used to perform various operations on a PDF document without access to its inner structure.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Pdf.v21.1.Core.dll

NuGet Package: DevExpress.Pdf.Core

Declaration

public class PdfDocumentFacade

Remarks

Change AcroForm Field Options

The AcroForm property obtains a set of methods used to organize interactive forms.

Utilize one of the following methods to get form field properties:

Method Description
PdfAcroFormFacade.GetFields() Retrieves all AcroForm fields.
GetFormField() Obtains properties of a field with a specific name.
GetButtonFormField()
GetCheckBoxFormField()
GetComboBoxFormField()
and so on
Returns properties of a specific form field type.

Utilize the PdfAcroFormFacade.GetNames() method to get a list of form field names.

The code sample below retrieves all fields and changes their appearance:

using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor())
{
    pdfDocumentProcessor.LoadDocument("Documents//FormDemo.pdf");

    PdfDocumentFacade documentFacade = pdfDocumentProcessor.DocumentFacade;
    PdfAcroFormFacade acroForm = documentFacade.AcroForm;

    //Change color settings for all form fields:
    var fields = acroForm.GetFields();
    foreach (PdfFormFieldFacade field in fields)
    {
        ChangeFormFieldColor(field);
    }
    pdfDocumentProcessor.SaveDocument("FormDemo_new.pdf");
}
  private static void ChangeFormFieldColor(PdfFormFieldFacade field)
  {
      foreach (PdfWidgetFacade pdfWidget in field)
      {
          //Change color and border settings
          //for all form fields:
          pdfWidget.BorderWidth = 1;
          pdfWidget.BackgroundColor = new PdfRGBColor(0.81, 0.81, 0.81);
          pdfWidget.BorderColor = new PdfRGBColor(0.47, 0.44, 0.67);
          pdfWidget.FontColor = new PdfRGBColor(0.34, 0.25, 0.36);

          //Change border style for text form fields:
          if (field.Type == PdfFormFieldType.Text)
          {
              pdfWidget.BorderStyle = PdfBorderStyle.Underline;
          }
      }
  }

Flatten Annotations

The PdfDocumentFacade allows you to flatten all document annotations and annotations on a specific page. Call the PdfDocumentFacade.FlattenAnnotations() method to flatten document annotations. The code sample below flattens all text annotations in the document:

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
  // Load a document:
  processor.LoadDocument("..\\..\\Document.pdf");

  // Flatten all text annotations:
  PdfDocumentFacade documentFacade = processor.DocumentFacade;
  documentFacade.FlattenAnnotations(PdfAnnotationType.Text);

  // Save the result:
  processor.SaveDocument("..\\..\\Result.pdf");
}

The PdfDocumentFacade.Pages property returns a list of objects used to organize the PDF page without access to its inner structure. Call the PdfPageFacade.FlattenAnnotations() method to flatten the page annotations.

The code sample below flattens all annotations that are located on the lower half of the page:

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
  // Load a document:
  processor.LoadDocument("..\\..\\Document.pdf");

  // Flatten annotations located
  // on the lower half of the page:
  PdfPageFacade pageFacade = documentFacade.Pages[0];

  double halfPage = processor.Document.Pages[0].CropBox.Top / 2;
  pageFacade.FlattenAnnotations(x => x.Rectangle.Top < halfPage);

  // Save the result:
  processor.SaveDocument("..\\..\\Result.pdf");
}

You can also flatten a specific annotation. Use the PdfPageFacade.Annotations property to retrieve a list of annotation facade objects and utilize the PdfAnnotationFacade.Flatten() method.

The code sample below flattens the first annotation on the page:

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
  // Load a document:
  processor.LoadDocument("..\\..\\Document.pdf");

  // Flatten the first annotation:
  var annotations = processor.DocumentFacade.Pages[0].Annotations;
  annotations[0].Flatten();

  // Save the result:
  processor.SaveDocument("..\\..\\Result.pdf");
}

Inheritance

Object
PdfDocumentFacade
See Also