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
| Format | Constant | Description |
|---|---|---|
| FDF | FSFDFDocFDF | Forms Data Format (binary) |
| XFDF | FSFDFDocXFDF | XML FDF |
FSFDFDoc APIs:
| Method | Description |
|---|---|
initWithType: | Create empty FDF (FSFDFDocFDF or FSFDFDocXFDF) |
initWithPath: | Load from path |
getType | Format type |
isEmpty | Empty 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
| Scenario | Approach |
|---|---|
| Collaborative review — share annotations | Export XFDF, distribute, import locally |
| Server-side annotation processing | XFDF for parsing and storage |
| Final publish — non-editable annotations | Export backup, then flatten all |
| Archival — consistent rendering | Flatten annotations and form fields |