Skip to content

Shapes and drawing ​

This guide covers Line, Square, Circle, Polygon, PolyLine, and Ink annotations.

Line annotations ​

Lines run from start to end with optional endpoint styles (arrows, etc.).

Endpoint styles ​

Set via FSMarkup constants:

ConstantValueDescription
FSMarkupEndingStyleNone0None
FSMarkupEndingStyleSquare1Square
FSMarkupEndingStyleCircle2Circle
FSMarkupEndingStyleDiamond3Diamond
FSMarkupEndingStyleOpenArrow4Open arrow
FSMarkupEndingStyleClosedArrow5Closed arrow
FSMarkupEndingStyleButt6Butt
FSMarkupEndingStyleROpenArrow7Reverse open arrow
FSMarkupEndingStyleRClosedArrow8Reverse closed arrow
FSMarkupEndingStyleSlash9Slash

Core methods ​

MethodDescription
getStartPoint / setStartPoint:Start point
getEndPoint / setEndPoint:End point
getLineStartStyle / setLineStartStyle:Start style
getLineEndStyle / setLineEndStyle:End style
getStyleFillColor / setStyleFillColor:Endpoint fill
hasCaption / enableCaption:Caption
getCaptionOffset / setCaptionOffset:Caption offset

Example: line with arrow ​

objc
#import <FoxitRDK/FSPDFObjC.h>

FSPDFPage *page = [doc getPage:0];

FSRectF *rect = [[FSRectF alloc] initWithLeft1:100 bottom1:300 right1:400 top1:350];
FSAnnot *annot = [page addAnnot:FSAnnotLine rect:rect];
FSLine *line = [[FSLine alloc] initWithAnnot:annot];

FSPointF *startPt = [[FSPointF alloc] init];
[startPt set:100 y:325];
FSPointF *endPt = [[FSPointF alloc] init];
[endPt set:400 y:325];

[line setStartPoint:startPt];
[line setEndPoint:endPt];

[line setLineStartStyle:FSMarkupEndingStyleNone];
[line setLineEndStyle:FSMarkupEndingStyleClosedArrow];

[line setBorderColor:0xFFFF0000];
[line setContent:@"Watch out this section"];
[line resetAppearanceStream];

Square and circle ​

Both support border and fill colors.

Example: square ​

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

FSRectF *rect = [[FSRectF alloc] initWithLeft1:100 bottom1:600 right1:300 top1:700];
FSAnnot *annot = [page addAnnot:FSAnnotSquare rect:rect];
FSSquare *square = [[FSSquare alloc] initWithAnnot:annot];

[square setBorderColor:0xFF0000FF];
[square setFillColor:0x330000FF];
[square setOpacity:0.8f];
[square setContent:@"marked section"];
[square resetAppearanceStream];

Example: circle ​

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

FSRectF *rect = [[FSRectF alloc] initWithLeft1:100 bottom1:400 right1:250 top1:500];
FSAnnot *annot = [page addAnnot:FSAnnotCircle rect:rect];
FSCircle *circle = [[FSCircle alloc] initWithAnnot:annot];

[circle setBorderColor:0xFFFF6600];
[circle setFillColor:0x22FF6600];
[circle setContent:@"Key Content"];
[circle resetAppearanceStream];

Polygon and polyline ​

Vertices define the shape; polygons close; polylines stay open.

Example: polygon ​

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

FSRectF *rect = [[FSRectF alloc] initWithLeft1:100 bottom1:200 right1:300 top1:350];
FSAnnot *annot = [page addAnnot:FSAnnotPolygon rect:rect];
FSMarkup *polygon = [[FSMarkup alloc] initWithAnnot:annot];

FSPointFArray *vertices = [[FSPointFArray alloc] init];
FSPointF *p1 = [[FSPointF alloc] init]; [p1 set:150 y:200];
FSPointF *p2 = [[FSPointF alloc] init]; [p2 set:300 y:250];
FSPointF *p3 = [[FSPointF alloc] init]; [p3 set:280 y:350];
FSPointF *p4 = [[FSPointF alloc] init]; [p4 set:120 y:330];
[vertices add:p1];
[vertices add:p2];
[vertices add:p3];
[vertices add:p4];
[polygon setVertexes:vertices];

[polygon setBorderColor:0xFF009900];
[polygon resetAppearanceStream];

Ink annotations ​

Ink stores freehand strokes via FSPath.

FSPath ​

MethodDescription
moveTo:Start stroke
lineTo:Line to point
cubicBezierTo:point2:point3:Cubic Bézier
closeFigureClose path
getPointCount / getPoint:Point access

Example: ink ​

objc
#import <FoxitRDK/FSPDFObjC.h>

FSPDFPage *page = [doc getPage:0];

FSRectF *rect = [[FSRectF alloc] initWithLeft1:50 bottom1:100 right1:350 top1:300];
FSAnnot *annot = [page addAnnot:FSAnnotInk rect:rect];
FSInk *ink = [[FSInk alloc] initWithAnnot:annot];

FSPath *path = [[FSPath alloc] init];
FSPointF *pt1 = [[FSPointF alloc] init]; [pt1 set:60 y:150];
FSPointF *pt2 = [[FSPointF alloc] init]; [pt2 set:120 y:200];
FSPointF *pt3 = [[FSPointF alloc] init]; [pt3 set:200 y:160];
FSPointF *pt4 = [[FSPointF alloc] init]; [pt4 set:300 y:250];
[path moveTo:pt1];
[path lineTo:pt2];
[path lineTo:pt3];
[path lineTo:pt4];

[ink setInkList:path];
[ink setBorderColor:0xFF000000];
[ink setOpacity:0.9f];
[ink resetAppearanceStream];

NOTE

Call [ink enableUseBezier:YES] for smoother strokes with Bézier curves.