# # Import and Export

## # Annotation

The Annotation supports three types of files to import/export data: XFDF, FDF and JSON. The following table lists what annotations currently support or not support to import/export.

File Type | If all annots support | What not support
--- | --- | ---
XFDF/FDF | Mostly | Screen Image, Link, Sound
JSON | Mostly | Screen Image, Link, Sound

### # API

The following table list methods that can be used to import/export from/to data file.

Method | XFDF/FDF | JSON | JSON
--- | --- | --- | ---
Import | PDFDoc.importAnnotsFromFDF() | PDFDoc.importAnnotsFromJSON(annotsJson) | PDFPage.addAnnot(annotJson)
Export | PDFDoc.exportAnnotsToFDF() | PDFDoc.exportAnnotsToJSON() | Annot.exportToJson()

It is recommended to use a corresponding method to import and export data. For example, If `PDFDoc.exportAnnotsToJSON()` is called to export data, then it would better the `PDFDoc.importAnnotsFromJSON(annotsJson)`is used to import.

Note: Adding exported JSON data to the document via the `PDFPage.addAnnot` method can lead to loss of binary data streams for some annotations, such as Stamp and fileAttachment. This is because the `PDFPage.addAnnot` method does not support JSON data that contains binary streams. Therefore, if the data exported by `PDFDoc.exportAnnotsToJSON` contains binary streams, then it cannot be passed to the `PDFPage.addAnnot` method.

    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]);
    }

## # Form

The Form supports five standard types of files to import/export data: XFDF, FDF, XML, CSV and Txt.

### # API

The following table list APIs that Foxit PDF SDK for Web provides to import/export data file.

- PDFDoc.exportFormToFile()
- PDFDoc.importFormFromFile()