Foxit PDF SDK for Windows

How to Annotate PDFs using Foxit PDF SDK (.NET)

General

An annotation associates an object such as note, line, and highlight with a location on a page of a PDF document. It provides a way to interact with users by means of the mouse and keyboard. PDF includes a wide variety of standard annotation types as listed in Table 3-1. Among these annotation types, many of them are defined as markup annotations for they are used primarily to mark up PDF documents. These annotations have text that appears as part of the annotation and may be displayed in other ways by a conforming reader, such as in a Comments pane. The ‘Markup’ column in Table 3-1 shows whether an annotation is a markup annotation.

Foxit PDF SDK supports most annotation types defined in PDF reference. PDF SDK provides APIs of annotation creation, properties access and modification, appearance setting and drawing.

Table 3-1

Annotation type Description Markup Supported by SDK
Text(Note) Text annotation Yes Yes
Link Link Annotations No Yes
FreeText
(TypeWriter/TextBox/Callout)
Free text annotation Yes Yes
Line Line annotation Yes Yes
Square Square annotation Yes Yes
Circle Circle annotation Yes Yes
Polygon Polygon annotation Yes Yes
PolyLine PolyLine annotation Yes Yes
Highlight Highlight annotation Yes Yes
Underline Underline annotation Yes Yes
Squiggly Squiggly annotation Yes Yes
StrikeOut StrikeOut annotation Yes Yes
Stamp Stamp annotation Yes Yes
Caret Caret annotation Yes Yes
Ink(pencil) Ink annotation Yes Yes
Popup Popup annotation No Yes
File Attachment FileAttachment annotation Yes Yes
Sound Sound annotation Yes No
Movie Movie annotation No No
Widget* Widget annotation No Yes
Screen Screen annotation No Yes
PrinterMark PrinterMark annotation No No
TrapNet Trap network annotation No No
Watermark* Watermark annotation No Yes
3D 3D annotation No No
Redact Redact annotation Yes Yes

Note:

  1. The annotation widget and watermark are special. They aren’t supported in the module of ‘Annotation’. This type of widget is only used in the module as a ‘form filler’ and the watermark in the module of ‘watermark’.
  2. Foxit SDK supports a customized annotation type called PSI (pressure sensitive ink) annotation. Usually, PSI is for handwriting features and Foxit SDK treats it as a PSI annotation so that it can be handled by other PDF products.

Example:

How to add a link annotation to another page in the same PDF

using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
using foxit.pdf.graphics;
using foxit.pdf.annots;
using foxit.pdf.actions;
...

// Assuming PDFPage page has been loaded and parsed.
Annot annot = page.AddAnnot(Annot.Type.e_Link, new RectF(350, 350, 380, 400))
Link link = new Link(annot);
link.SetHighlightingMode(Annot.HighlightingMode.e_HighlightingToggle);

// Appearance should be reset.
link.ResetAppearanceStream();
...

How to add a highlight annotation to a page and set the related annotation properties

using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
using foxit.pdf.graphics;
using foxit.pdf.annots;
using foxit.pdf.actions;
...

// Assuming PDFPage page has been loaded and parsed.

// Add highlight annotation.
Annot annot = page.AddAnnot(Annot.Type.e_Highlight, new RectF(10, 450, 100, 550));
Highlight highlight = new Highlight(annot);
highlight.SetContent("Highlight");
QuadPoints quad_points = new QuadPoints();
quad_points.first = new foxit.common.fxcrt.PointF(10, 500);
quad_points.second = new foxit.common.fxcrt.PointF(90, 500);
quad_points.third = new foxit.common.fxcrt.PointF(10, 480);
quad_points.fourth = new foxit.common.fxcrt.PointF(90, 480);
QuadPointsArray quad_points_array = new QuadPointsArray();
quad_points_array.Add(quad_points);
highlight.SetQuadPoints(quad_points_array);
highlight.SetSubject("Highlight");
highlight.SetTitle("Foxit SDK");
highlight.SetCreationDateTime(GetLocalDateTime());
highlight.SetModifiedDateTime(GetLocalDateTime());
highlight.SetUniqueID(RandomUID());

// Appearance should be reset.
highlight.ResetAppearanceStream();
...

How to set the popup information when creating markup annotations

using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
using foxit.pdf.graphics;
using foxit.pdf.annots;
using foxit.pdf.actions;
...

// Assuming PDFPage page has been loaded and parsed.
// Assuming the annnots in the page have been loaded.
// Create a new note annot and set the properties for it.
Annot annot = page.AddAnnot(Annot.Type.e_Note, new RectF(10, 350, 50, 400));
Note note = new Note(annot);
note.SetIconName("Comment");
note.SetSubject("Note");
note.SetTitle("Foxit SDK");
note.SetContent("Note annotation.");
note.SetCreationDateTime(GetLocalDateTime());
note.SetModifiedDateTime(GetLocalDateTime());
note.SetUniqueID(RandomUID());

// Add popup to note annotation.
Annot annot_popup = page.AddAnnot(Annot.Type.e_Popup, new RectF(300, 450, 500, 550));
Popup popup = new Popup(annot); 
popup.SetBorderColor(0x00FF00);
popup.SetOpenStatus(false);
popup.SetModifiedDateTime(GetLocalDateTime());
note.SetPopup(popup);

// Appearance should be reset.
note.ResetAppearanceStream();
...

How to get a specific annotation in a PDF using device coordinates

using foxit;
using foxit.common;
using foxit.pdf;
using foxit.pdf.graphics;
using foxit.pdf.annots;
...

// Assuming PDFDoc doc has been loaded.
// Assuming PDFPage page has been loaded and parsed.
...
int width = (int)page.GetWidth();
int height = (int)page.GetHeight();
Matrix2D matrix = page.GetDisplayMatrix(0, 0, width, height, page.GetRotation());
// Assuming PointF point has been got.
float tolerance = 3.0f;
Annot annot = page.GetAnnotAtDevicePoint(point, tolerance, matrix);
...

Import annotations from or export annotations to a FDF file

With Foxit PDF SDK, annotations can be created with data not only from applications but also from FDF files. At the same time, PDF SDK supports annotation exporting to FDF files.

Example:

How to load annotations from a FDF file and add them into the first page of a given PDF

using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;

// Assuming PDFDoc doc has been loaded.
...
string fdf_file = "The FDF file path";
foxit.fdf.FDFDoc fdf_doc = new foxit.fdf.FDFDoc(fdf_file);
pdf_doc.ImportFromFDF(fdf_doc, (int)foxit.pdf.PDFDoc.DataType.e_Annots, new Range());
...

Image Conversion

Foxit PDF SDK provides APIs for conversion between PDF files and images. Applications could easily fulfill functionalities like image creation and image conversion which supports the following image formats: BMP, TIFF, PNG, JPX, JPEG, and GIF. Foxit PDF SDK can make the conversion between PDF files and the supported image formats except for GIF. It only supports converting GIF images to PDF files.

Example:

How to convert PDF pages to bitmap files

using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
using System.Drawing;

// Assuming PDFDoc doc has been loaded.
...
Image image = new Image();
// Get page count
int nPageCount = doc.GetPageCount();
for(int i=0;i

How to convert an image file to PDF file

using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
using System.Drawing;

// Assuming PDFDoc doc has been loaded.
...
Image image = new Image(input_file);
int count = image.GetFrameCount();
for (int i = 0; i < count; i++) {
PDFPage page = doc.InsertPage(i, PDFPage.Size.e_SizeLetter);
page.StartParse((int)PDFPage.ParseFlags.e_ParsePageNormal, null, false);

// Add image to page
page.AddImage(image, i, new PointF(0, 0), page.GetWidth(), page.GetHeight(), true);
}
doc.SaveAs(output_file, (int)PDFDoc.SaveFlags.e_SaveFlagNoOriginal);
...

Updated on April 16, 2019

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: