Skip to content

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 TypeConstantDescriptionMarkupSDK Support
Text (Note)Annot.e_NoteNote / text commentYesSupported
LinkAnnot.e_LinkHyperlinkNoSupported
FreeTextAnnot.e_FreeTextFree text (typewriter/text box/callout)YesSupported
LineAnnot.e_LineLine / arrowYesSupported
SquareAnnot.e_SquareRectangleYesSupported
CircleAnnot.e_CircleCircle / ellipseYesSupported
PolygonAnnot.e_PolygonPolygonYesSupported
PolyLineAnnot.e_PolyLinePolylineYesSupported
HighlightAnnot.e_HighlightText highlightYesSupported
UnderlineAnnot.e_UnderlineUnderlineYesSupported
SquigglyAnnot.e_SquigglySquiggly underlineYesSupported
StrikeOutAnnot.e_StrikeOutStrikethroughYesSupported
StampAnnot.e_StampStampYesSupported
CaretAnnot.e_CaretCaretYesSupported
InkAnnot.e_InkFreehand inkYesSupported
PopupAnnot.e_PopupPopup for annotation contentNoSupported
FileAttachmentAnnot.e_FileAttachmentFile attachmentYesSupported
SoundAnnot.e_SoundSoundYesNot supported
MovieAnnot.e_MovieMovieNoNot supported
WidgetAnnot.e_WidgetForm widgetNoSupported
ScreenAnnot.e_ScreenScreen / mediaNoSupported
PrinterMarkAnnot.e_PrinterMarkPrinter markNoNot supported
TrapNetAnnot.e_TrapNetTrap netNoNot supported
WatermarkAnnot.e_WatermarkWatermark annotationNoNot supported
3DAnnot.e_3D3DNoNot supported
RedactAnnot.e_RedactRedactionYesSupported

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
└── Popup

Annot Base — Common Properties

MethodDescription
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

MethodDescription
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