Skip to content

Import and export

Foxit PDF SDK for iOS imports and exports annotation data in FDF and XFDF formats for exchange between documents and systems. The SDK also flattens annotations into page content.

FDF and XFDF

FormatConstantDescription
FDFFSFDFDocFDFForms Data Format (binary)
XFDFFSFDFDocXFDFXML FDF

FSFDFDoc APIs:

MethodDescription
initWithType:Create empty FDF (FSFDFDocFDF or FSFDFDocXFDF)
initWithPath:Load from path
getTypeFormat type
isEmptyEmpty check
saveAs:Save to file

Export annotations

Export all

[FSPDFDoc exportToFDFDoc:data_type:range:]:

objc
#import <FoxitRDK/FSPDFObjC.h>

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

FSFDFDoc *fdfDoc = [[FSFDFDoc alloc] initWithType:FSFDFDocXFDF];
[doc exportToFDFDoc:fdfDoc data_type:FSPDFDocAnnots range:nil];
[fdfDoc saveAs:@"path/to/annotations.xfdf"];

NOTE

data_type FSPDFDocAnnots exports annotations. range (FSRange) limits pages; nil exports all pages.

Export one annotation

[FSPDFDoc exportAnnotToFDFDoc:annot:]:

objc
#import <FoxitRDK/FSPDFObjC.h>

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

FSAnnot *annot = [page getAnnot:0];

FSFDFDoc *fdfDoc = [[FSFDFDoc alloc] initWithType:FSFDFDocFDF];
[doc exportAnnotToFDFDoc:fdfDoc annot:annot];
[fdfDoc saveAs:@"path/to/single_annot.fdf"];

Import annotations

[FSPDFDoc importFromFDFDoc:data_type:range:]:

objc
#import <FoxitRDK/FSPDFObjC.h>

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

FSFDFDoc *fdfDoc = [[FSFDFDoc alloc] initWithPath:@"path/to/annotations.xfdf"];

[doc importFromFDFDoc:fdfDoc data_type:FSPDFDocAnnots range:nil];

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

Flatten annotations

Flattening merges annotation appearance into page content and removes the annotation objects (no longer selectable or editable).

Flatten all on a page

objc
#import <FoxitRDK/FSPDFObjC.h>

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

[page flattenAnnots:YES];

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

NOTE

YES flattens all annotations; NO flattens form fields only.

Flatten one annotation

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

if (annot && ![annot isEmpty]) {
    [page flattenAnnot:annot];
}

Typical scenarios

ScenarioApproach
Collaborative review — share annotationsExport XFDF, distribute, import locally
Server-side annotation processingXFDF for parsing and storage
Final publish — non-editable annotationsExport backup, then flatten all
Archival — consistent renderingFlatten annotations and form fields