Having trouble getting help?
Contact Support
Contact Support
Import and Export annotation
16 Jan 20252 minutes 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 in various formats such as objects, JSON, and XFDF.
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)="ExportAsJson()" >ExportAsJson</button>
<button (click)="ExportAsXfdf()" >ExportAsXfdf</button>
<button (click)="ExportAsObject()" >ExportAsObject</button>
<button (click)="Import()" >Import</button>
// export the annotation in JSON format.
ExportAsJson(): void {
var viewer = (<any>document.getElementById('pdfViewer')).ej2_instances[0];
viewer.exportAnnotation('Json');
}
// export the annotation in XFDF format.
ExportAsXfdf(): void {
var viewer = (<any>document.getElementById('pdfViewer')).ej2_instances[0];
viewer.exportAnnotation('Xfdf');
}
// export the annotation as object.
ExportAsObject(): void {
var viewer = (<any>document.getElementById('pdfViewer')).ej2_instances[0];
return viewer.exportAnnotationsAsObject().then((value: any) => {
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));
}