Import and Export annotation as object

4 Jan 20231 minute to read

The PDF Viewer library allows you to import annotations from objects or streams instead of loading it as a file. To import such annotation objects, the PDF Viewer control must export the PDF annotations as objects by using the ExportAnnotationsAsObject() method. Only the annotation objects that are exported from the PDF Viewer can be imported.

The following steps are used to import and export annotations as objects.

Step 1: Follow the steps provided in the link to create a simple PDF Viewer sample.

Step 2: Use the following code snippet to perform import and export annotation.

<button (click)="export()">Export Annotation</button>
<button (click)="import()">Import Annotation</button>
//export annotation as object.
export (): void {
  var viewer = (<any>document.getElementById('pdfViewer')).ej2_instances[0];
  viewer.exportAnnotationsAsObject().then(function (value) {
    exportObject = value;
  });
}

//import annotation that are exported as object.
import(): void {
  var viewer = (<any>document.getElementById('pdfViewer')).ej2_instances[0];
  viewer.importAnnotation(JSON.parse(exportObject));
}

Find the Sample, how to import and export annotation as object