Import and export ​
Annotations ​
Annotation data import and export supports three file formats: XFDF, FDF, and JSON. The table below lists annotation types that are not supported for import/export at this time.
| File type | All annotations supported? | Unsupported annotations |
|---|---|---|
| XFDF/FDF | Most | Screen Image, Link, Sound |
| JSON | Most | Screen Image, Link, Sound |
API ​
The table below lists Foxit PDF SDK for Web APIs for importing and exporting annotation data files.
| Method | XFDF/FDF | JSON | JSON |
|---|---|---|---|
| Import | PDFDoc.importAnnotsFromFDF() | PDFDoc.importAnnotsFromJSON(annotsJson) | PDFPage.AddAnnot(annotJson) |
| Export | PDFDoc.exportAnnotsToFDF() | PDFDoc.exportAnnotsToJSON() | Annot.exportToJson() |
RECOMMENDATION
Use matching import and export methods. For example, if you call PDFDoc.exportAnnotsToJSON() to export data, prefer PDFDoc.importAnnotsFromJSON(annotsJson) to import it.
WARNING
When importing data exported by PDFDoc.exportAnnotsToJSON() with PDFPage.addAnnot, binary streams for some annotations (such as Stamp and FileAttachment) may be lost because PDFPage.addAnnot does not support JSON that contains binary streams.
javascript
var pdfViewer = await pdfui.getPDFViewer();
var test = {ExportDataFile: 'http://pathToSourceFile.pdf', ImportDatafile: 'http://pathToTargetFile.pdf'};
var resp = await fetch(test.ExportDataFile);
var file = await resp.blob();
var pdfdoc = await pdfViewer.openPDFByFile(file);
var annotJson = await pdfdoc.exportAnnotsToJSON();
var newResp = await fetch(test.ImportDatafile);
var newFile = await newResp.blob()
var newPdfdoc = await pdfViewer.openPDFByFile(newFile);
for (var i = 0; i < annotJson.length; i++) {
var newPage = await newPdfdoc.getPageByIndex(annotJson[i].page);
var newAnnot = await newPage.addAnnot(annotJson[i]);
}