Quantcast
Channel: Developer Express Inc.
Viewing all articles
Browse latest Browse all 2370

PDF Document API – Annotation Enhancements (v21.2)

$
0
0

In our most recent major release (v21.2), we added annotation support to our PDF Document API and desktop PDF Viewers (both for WinForms and WPF). As you may recall, we implemented text annotation (sticky note) support in a previous release (v20.2). For background information on our implementation, please review the following blog post:

PDF – Sticky Notes and Comments

With v21.2, we expanded the list of supported annotation types and added new functionality to our Annotation Facade API. Our PDF API and our desktop PDF Viewers now support the following annotation types:

  • Link
  • Caret
  • Rubber Stamp (including dynamic and custom stamps)
  • Shape (circle, square)
  • File Attachment
  • Free Text (text box, callout, typewriter)
  • Ink
  • Path (line, arrows, polyline, polygon)

You can now create and delete annotations, edit associated content, flatten, add related comments and reviews. The API for previously supported annotation types (text highlights and sticky notes) are also available in our Facade API.

Note: You must own an active DevExpress Office File API Subscription or DevExpress Universal Subscription to use the functionality described herein across production software projects. For more information on Office File API licensing, please send an e-mail to clientservices@devexpress.com.

PDF Facade API

PdfPageFacade.Add[…]Annotation methods (AddCaretAnnotation, AddCirleAnnotation, etc.) allow you to generate all available annotation types.

The code sample below demonstrates how to create a rubber stamp, line, and a circle annotation:

using DevExpress.Pdf;

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

  // Access 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
  string icon = PdfRubberStampAnnotationIconName.Draft;
  PdfRubberStampAnnotationFacade rubberStamp =
  	pageFacade.AddRubberStampAnnotation(rubberStampRectangle, icon);
  rubberStamp.Author = "Nancy Skywalker";
  rubberStamp.Contents = "Made in PDF Document API";

  // Define line ending points
  PdfPoint point1 = new PdfPoint(430,500);
  PdfPoint point2 = new PdfPoint(430,470);

  // Create a line annotation
  PdfLineAnnotationFacade pdfLineAnnotation =
  	pageFacade.AddLineAnnotation(point1, point2);
  pdfLineAnnotation.Author = "Ryan Anita L";
  pdfLineAnnotation.Contents = "Please swap these statements";

  // Specify ending style and color
  pdfLineAnnotation.LineEndStyle = PdfAnnotationLineEndingStyle.OpenArrow;
  pdfLineAnnotation.LineStartStyle = PdfAnnotationLineEndingStyle.OpenArrow;
  pdfLineAnnotation.Color = new PdfRGBColor(0.23, 0.48, 0.34);
  pdfLineAnnotation.BorderWidth = 1.5; 

  // 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";
     circleAnnotation.Color = new PdfRGBColor(0.77, 0.38, 0.06);
     circleAnnotation.BorderWidth = 1.5;
  }

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

Use the PdfPageFacade.Annotations property to access all page annotation properties. You can filter annotation properties, cast them to a corresponding PdfAnnotationFacade class descendant, and use class properties to modify annotation parameters. Refer to the following help topics for additional information and examples:

Annotations in PDF Documents

The Facade API is also available in our PDF Viewers (WinForms and WPF). Call the PdfViewerExtensions.GetDocumentFacade method to retrieve the DocumentFacade object. Add the DevExpress.Docs.v21.2.dll assembly to your project to use extension methods. Once again, please remember that you must own an active Office File API or Universal Subscription to use this assembly in production code.

Try It Now

To explore PDF Annotations feature in greater detail, be sure to check out our new Office File API demo module:

PDF Rubber Stamp Annotations

This demo allows you to create and edit rubber stamp annotations. You can add a predefined stamp (from Standard Business or Sign Here categories) or a dynamic stamp (indicate name, date, and time information). To create a custom rubber stamp, select one of the document stamps, and click Set Custom Icon in the invoked property grid.

Your Feedback Matters

We’d love to know what you think of our PDF annotation support within our Office-inspired product line. Please share your thoughts in the comment section below or submit a support ticket via the DevExpress Support Center.


Viewing all articles
Browse latest Browse all 2370

Trending Articles