Skip to content

Page objects ​

Foxit PDF SDK for iOS provides graphics object APIs via Core SDK to add, modify, and remove text, image, and path objects on pages.

Core classes ​

ClassDescription
FSGraphicsObjectsPage graphics collection from [FSPDFPage getGraphicsObjects]
FSGraphicsObjectGraphics object base class
FSTextObjectText object
FSImageObjectImage object from bitmap or image
FSPathObjectPath object for custom shapes

Example: add a text object ​

objc
#import <FoxitRDK/FSPDFObjC.h>

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

// Create text object
FSTextObject *textObj = [FSTextObject create];

// Text
[textObj setText:@"Hello, Foxit!"];

// Font and style
FSTextState *textState = [[FSTextState alloc] init];
[textState setFont:[[FSFont alloc] initWithStandard_id:FSFontStdIDHelvetica]];
[textState setFont_size:24.0f];
[textState setTextcolor:0xFF000000];
[textObj setTextState:page text_state:textState is_italic:NO weight:400];

// Position
FSMatrix2D *matrix = [[FSMatrix2D alloc] initWithA1:1 b1:0 c1:0 d1:1 e1:100 f1:700];
[textObj setMatrix:matrix];

// Add to page
FSGraphicsObjects *graphicsObjects = [page getGraphicsObjects];
[graphicsObjects insertObject:FSGraphicsObject.e_TypeText index:-1 graphics_object:textObj];
[page generateContent];

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

Example: add an image object ​

objc
// Create image object
FSImageObject *imageObj = [FSImageObject create:doc];

// Load image
FSImage *image = [[FSImage alloc] initWithPath:@"path/to/image.png"];
[imageObj setImage:image frame_index:0];

// Position and size
FSMatrix2D *matrix = [[FSMatrix2D alloc] initWithA1:200 b1:0 c1:0 d1:200 e1:100 f1:400];
[imageObj setMatrix:matrix];

// Add to page
FSGraphicsObjects *graphicsObjects = [page getGraphicsObjects];
[graphicsObjects insertObject:FSGraphicsObject.e_TypeImage index:-1 graphics_object:imageObj];
[page generateContent];

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

API reference

See the API reference for FSTextObject, FSImageObject, FSPathObject, and FSGraphicsObjects.