Annotations Overview
Foxit PDF SDK for Android supports most PDF annotation types through the Core SDK, including create, property access, appearance generation, and rendering.
Built-in annotations in UI Extensions
If you use the full reader (UI Extensions), common annotations (highlight, note, drawing, stamp, etc.) are available from the toolbar without extra code. This guide focuses on programmatic annotation control.
Annotation Types
| Annotation Type | Constant | Description | Markup | SDK Support |
|---|---|---|---|---|
| Text (Note) | Annot.e_Note | Note / text comment | Yes | Supported |
| Link | Annot.e_Link | Hyperlink | No | Supported |
| FreeText | Annot.e_FreeText | Free text (typewriter/text box/callout) | Yes | Supported |
| Line | Annot.e_Line | Line / arrow | Yes | Supported |
| Square | Annot.e_Square | Rectangle | Yes | Supported |
| Circle | Annot.e_Circle | Circle / ellipse | Yes | Supported |
| Polygon | Annot.e_Polygon | Polygon | Yes | Supported |
| PolyLine | Annot.e_PolyLine | Polyline | Yes | Supported |
| Highlight | Annot.e_Highlight | Text highlight | Yes | Supported |
| Underline | Annot.e_Underline | Underline | Yes | Supported |
| Squiggly | Annot.e_Squiggly | Squiggly underline | Yes | Supported |
| StrikeOut | Annot.e_StrikeOut | Strikethrough | Yes | Supported |
| Stamp | Annot.e_Stamp | Stamp | Yes | Supported |
| Caret | Annot.e_Caret | Caret | Yes | Supported |
| Ink | Annot.e_Ink | Freehand ink | Yes | Supported |
| Popup | Annot.e_Popup | Popup for annotation content | No | Supported |
| FileAttachment | Annot.e_FileAttachment | File attachment | Yes | Supported |
| Sound | Annot.e_Sound | Sound | Yes | Not supported |
| Movie | Annot.e_Movie | Movie | No | Not supported |
| Widget | Annot.e_Widget | Form widget | No | Supported |
| Screen | Annot.e_Screen | Screen / media | No | Supported |
| PrinterMark | Annot.e_PrinterMark | Printer mark | No | Not supported |
| TrapNet | Annot.e_TrapNet | Trap net | No | Not supported |
| Watermark | Annot.e_Watermark | Watermark annotation | No | Not supported |
| 3D | Annot.e_3D | 3D | No | Not supported |
| Redact | Annot.e_Redact | Redaction | Yes | Supported |
INFO
The SDK also supports custom PSI (Pressure Sensitive Ink, Annot.e_PSInk), not defined in the PDF spec, often used for handwriting.
The SDK does not support the PDF Watermark annotation type, but supports watermarks as page content—see Watermarks.
Class Hierarchy
Annot ← Base for all annotations
├── Markup ← Markup features (title, subject, opacity, replies, grouping, etc.)
│ ├── TextMarkup ← Highlight / Underline / StrikeOut / Squiggly
│ ├── FreeText
│ ├── Note
│ ├── Line
│ ├── Square
│ ├── Circle
│ ├── Ink
│ ├── Stamp
│ ├── Caret
│ ├── FileAttachment
│ └── Redact
├── Link
├── Screen
├── Widget
└── PopupAnnot Base — Common Properties
| Method | Description |
|---|---|
getType() | Type constant (e.g. Annot.e_Note) |
getPage() | Page |
getRect() / setRect(RectF) | Bounding rect |
move(RectF) | Move |
getContent() / setContent(String) | Text content |
getBorderColor() / setBorderColor(int) | Border color |
getBorderInfo() / setBorderInfo(BorderInfo) | Border width, style, dash |
getFlags() / setFlags(int) | Flags (hidden, locked, etc.) |
getUniqueID() / setUniqueID(String) | Unique ID |
getModifiedDateTime() / setModifiedDateTime(DateTime) | Modified time |
resetAppearanceStream() | Regenerate appearance (required after property changes) |
isEmpty() | Empty check |
Important
Call resetAppearanceStream() after changing properties so appearance updates take effect.
Markup Base — Extended Properties
| Method | Description |
|---|---|
getTitle() / setTitle(String) | Author/title |
getSubject() / setSubject(String) | Subject |
getOpacity() / setOpacity(float) | Opacity (0.0 ~ 1.0) |
getIntent() / setIntent(String) | Intent (e.g. FreeText subtypes) |
getCreationDateTime() / setCreationDateTime(DateTime) | Creation time |
getPopup() / setPopup(Popup) | Popup |
getReplyCount() | Reply count |
getReply(int) / addReply() / removeReply(int) | Replies (Note type) |
removeAllReplies() | Remove all replies |
isGrouped() | In a group |
getGroupHeader() / getGroupElements() / ungroup() | Grouping |
getStateAnnots(int) / addStateAnnot(...) | State annotations |
Create Annotations
Use PDFPage.addAnnot():
java
import com.foxit.sdk.common.fxcrt.RectF;
import com.foxit.sdk.pdf.PDFDoc;
import com.foxit.sdk.pdf.PDFPage;
import com.foxit.sdk.pdf.annots.Annot;
import com.foxit.sdk.pdf.annots.Note;
PDFDoc doc = new PDFDoc("path/to/Sample.pdf");
doc.load(null);
PDFPage page = doc.getPage(0);
RectF rect = new RectF(100, 100, 130, 130);
Note note = new Note(page.addAnnot(Annot.e_Note, rect));
note.setIconName("Comment");
note.setBorderColor(0xff0000ff);
note.setContent("这是一条便笺注释。");
note.resetAppearanceStream();
doc.saveAs("path/to/output.pdf", PDFDoc.e_SaveFlagNormal);Delete Annotations
java
PDFPage page = doc.getPage(0);
Annot annot = page.getAnnot(0);
if (annot != null && !annot.isEmpty()) {
page.removeAnnot(annot);
}Annotation Event Listener
Register AnnotEventListener via UI Extensions DocumentManager:
java
import com.foxit.sdk.pdf.PDFPage;
import com.foxit.sdk.pdf.annots.Annot;
import com.foxit.uiextensions.UIExtensionsManager;
import com.foxit.uiextensions.annots.AnnotEventListener;
AnnotEventListener listener = new AnnotEventListener() {
@Override
public void onAnnotAdded(PDFPage page, Annot annot) {
}
@Override
public void onAnnotWillDelete(PDFPage page, Annot annot) {
}
@Override
public void onAnnotDeleted(PDFPage page, Annot annot) {
}
@Override
public void onAnnotModified(PDFPage page, Annot annot) {
}
@Override
public void onAnnotChanged(Annot lastAnnot, Annot currentAnnot) {
}
};
UIExtensionsManager uiExtensionsManager = ...;
uiExtensionsManager.getDocumentManager().registerAnnotEventListener(listener);NOTE
Use unregisterAnnotEventListener(listener) to unregister. Unregister when the Activity is destroyed to avoid leaks.
More Annotation Types
- Text Markup — Highlight, underline, strikethrough, squiggly
- Note and FreeText — Note, typewriter, text box, callout, caret
- Shapes and Drawing — Line, rectangle, circle, polygon, polyline, ink
- Stamps — Standard and custom stamps
- Links — URI and go-to page
- Redaction — Create and apply redaction
- Import and Export — FDF/XFDF and flattening