Skip to content

Text markup annotations ​

Text markup annotations visually mark existing PDF text. Foxit PDF SDK for iOS provides highlight, underline, strikethrough, and squiggly via FSTextMarkup and subtypes.

TypeConstantDescription
HighlightFSAnnotHighlightSemi-transparent overlay
UnderlineFSAnnotUnderlineUnderline
StrikethroughFSAnnotStrikeOutStrikethrough
SquigglyFSAnnotSquigglySquiggly underline

QuadPoints ​

Text markup positioning uses QuadPoints (four corners per region). Multiple quads form FSQuadPointsArray for multi-line or multi-region text.

first ──────── second
  │               │
third ──────── fourth
  • first — top-left
  • second — top-right
  • third — bottom-left
  • fourth — bottom-right

You can create with an empty rect (0, 0, 0, 0); the annot rect is computed from QuadPoints.

Example: highlight from search results ​

objc
#import <FoxitRDK/FSPDFObjC.h>

FSPDFDoc *doc = [[FSPDFDoc alloc] initWithPath:@"path/to/Sample.pdf"];
[doc load:nil];
FSPDFPage *page = [doc getPage:0];

FSTextSearch *textSearch = [[FSTextSearch alloc] initWithDocument:doc cancel_callback:nil];
[textSearch setPattern:@"foxit"];

if ([textSearch findNext]) {
    FSRectFArray *rects = [textSearch getMatchRects];

    FSQuadPointsArray *quadPointsArray = [[FSQuadPointsArray alloc] init];
    for (int i = 0; i < [rects getSize]; i++) {
        FSRectF *rect = [rects getAt:i];
        FSQuadPoints *qp = [[FSQuadPoints alloc] init];
        FSPointF *first = [[FSPointF alloc] init];
        [first set:[rect getLeft] y:[rect getTop]];
        FSPointF *second = [[FSPointF alloc] init];
        [second set:[rect getRight] y:[rect getTop]];
        FSPointF *third = [[FSPointF alloc] init];
        [third set:[rect getLeft] y:[rect getBottom]];
        FSPointF *fourth = [[FSPointF alloc] init];
        [fourth set:[rect getRight] y:[rect getBottom]];
        [qp setFirst:first];
        [qp setSecond:second];
        [qp setThird:third];
        [qp setFourth:fourth];
        [quadPointsArray add:qp];
    }

    FSRectF *emptyRect = [[FSRectF alloc] initWithLeft1:0 bottom1:0 right1:0 top1:0];
    FSAnnot *annot = [page addAnnot:FSAnnotHighlight rect:emptyRect];
    FSTextMarkup *highlight = [[FSTextMarkup alloc] initWithAnnot:annot];

    [highlight setQuadPoints:quadPointsArray];
    [highlight setBorderColor:0xFFFF0000];
    [highlight setOpacity:0.3f];
    [highlight resetAppearanceStream];
}

[doc saveAs:@"path/to/output.pdf" saveFlags:FSPDFDocSaveFlagNormal];

Example: underline with known coordinates ​

objc
FSPDFPage *page = [doc getPage:0];

FSQuadPoints *qp = [[FSQuadPoints alloc] init];
FSPointF *first = [[FSPointF alloc] init];
[first set:72 y:750];
FSPointF *second = [[FSPointF alloc] init];
[second set:300 y:750];
FSPointF *third = [[FSPointF alloc] init];
[third set:72 y:730];
FSPointF *fourth = [[FSPointF alloc] init];
[fourth set:300 y:730];
[qp setFirst:first];
[qp setSecond:second];
[qp setThird:third];
[qp setFourth:fourth];

FSQuadPointsArray *quadPointsArray = [[FSQuadPointsArray alloc] init];
[quadPointsArray add:qp];

FSRectF *emptyRect = [[FSRectF alloc] initWithLeft1:0 bottom1:0 right1:0 top1:0];
FSAnnot *annot = [page addAnnot:FSAnnotUnderline rect:emptyRect];
FSTextMarkup *underline = [[FSTextMarkup alloc] initWithAnnot:annot];
[underline setQuadPoints:quadPointsArray];
[underline setBorderColor:0xFF00AA00];
[underline resetAppearanceStream];

Tip

Use FSAnnotStrikeOut or FSAnnotSquiggly instead of FSAnnotUnderline; the rest of the code is the same.

Common properties ​

MethodDescription
getQuadPoints / setQuadPoints:Quad array
setBorderColor:Mark color
setOpacity:Opacity (0.0–1.0)
setContent:Comment text in panel
setTitle:Author / title
resetAppearanceStreamUpdate appearance