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.v24.2.Core.dll
NuGet Package: DevExpress.Pdf.Core
#Declaration
#Related API Members
The following members return PdfDocumentFacade objects:
#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 |
---|---|
Pdf |
Retrieves all Acro |
Get |
Obtains properties of a field with a specific name. |
Get Get Get 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;
}
}
}
#Manage Annotations
You can create and delete annotations, edit their content, flatten, add related comments and reviews. Refer to the following topic for more information about annotations: Annotations in PDF Documents.
#Create Annotations
The PdfPageFacade.Annotations property retrieves all page annotation properties. Use the PdfDocumentFacade.Pages property to access the PdfPageFacade class.
The table below lists available annotation types and API used to create these annotations:
The code sample below creates a rubber stamp, file attachment, free text, and a circle annotation:
using DevExpress.Pdf;
using System;
using System.IO;
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
// Load a document
processor.LoadDocument("..\\..\\Document.pdf");
// Access the first page properties
PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];
// Define a rubber stamp rectangle
PdfRectangle rubberStampRectangle = new PdfRectangle(663, 526, 763, 576);
// Create a "Draft" rubber stamp annotation
PdfRubberStampAnnotationFacade rubberStamp =
pageFacade.AddRubberStampAnnotation(rubberStampRectangle,
PdfRubberStampAnnotationIconName.Draft);
rubberStamp.Author = "Jesse Faden";
rubberStamp.Contents = "Made in PDF Document API";
// Define a file attachment area
PdfPoint attachmentPoint = new PdfPoint(52, 550);
// Specify attachment data
PdfFileAttachment attachment = new PdfFileAttachment()
{
CreationDate = DateTime.Now,
Description = "This is my attached file",
FileName = "MyAttach.txt",
Data = File.ReadAllBytes("..\\..\\FileToAttach.txt")
};
// Create a file attachment annotation
PdfFileAttachmentAnnotationFacade pdfFileAttachment =
pageFacade.AddFileAttachmentAnnotation(attachmentPoint, attachment,
PdfFileAttachmentAnnotationIconName.PaperClip);
pdfFileAttachment.Author = "Nancy Skywalker";
pdfFileAttachment.Contents = "Additional Content";
// Specify a free text annotation area
PdfRectangle freeTextRectangle = new PdfRectangle(14, 321, 145, 340);
// Create a free text annotation in this area
PdfFreeTextAnnotationFacade freeTextAnnotation =
pageFacade.AddFreeTextAnnotation(freeTextRectangle, "Free Text Annotation");
freeTextAnnotation.Author = "Rayn Anita W";
// Add a callout line
freeTextAnnotation.SetCallout(PdfAnnotationLineEndingStyle.OpenArrow, new PdfPoint(152,351));
// Find the target phrase in the document
string circleText = "dogfooded";
PdfTextSearchResults searchResults = processor.FindText(circleText);
if (searchResults.Status == PdfTextSearchStatus.Found)
{
// Define an area around the phrase to add an annotation
PdfRectangle circleRectangle = searchResults.Rectangles[0].BoundingRectangle;
// Create a circle annotation in this area
PdfCircleAnnotationFacade circleAnnotation = pageFacade.AddCircleAnnotation(circleRectangle);
circleAnnotation.Author = "Cardle Anita W";
circleAnnotation.Contents = "It's better to say 'used' in this case";
}
// Save the result
processor.SaveDocument("..\\..\\Result.pdf");
}
#Flatten Annotations
Call one of the following methods to flatten an annotation:
Method | Description |
---|---|
Pdf |
Flattens document annotations. |
Pdf |
Flattens annotations of a specific page. |
Pdf |
Flattens a specific annotation. |
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");
}