How to Show and Hide Annotations in the Angular PDF Viewer?
Description:
This article outlines how to control the visibility of annotations in the Angular PDF Viewer, providing simple and efficient steps to show or hide them.
Solution:
The Angular PDF Viewer does not directly support hiding and unhiding annotations. However, you can achieve this by exporting annotations using the exportAnnotationsAsObject
method, temporarily removing them to hide, and re-importing the saved annotations using the importAnnotations
method when needed. This provides an efficient way to manage annotation visibility.
Code Snippets:
app.component.html:
<div class="content-wrapper">
<button (click)="HideAnnotations()">Hide Annotations</button>
<button (click)="UnHideAnnotations()">Unhide Annotations</button>
<ejs-pdfviewer
#pdfviewer
id="pdfViewer"
[documentPath]="document"
[resourceUrl]="resource"
style="height:640px;display:block"
></ejs-pdfviewer>
</div>
app.component.ts:
public exportObject: any;
HideAnnotations() {
var proxy = this;
var viewer = (<any>document.getElementById('pdfViewer')).ej2_instances[0];
viewer.exportAnnotationsAsObject().then(function (value) {
proxy.exportObject = value;
viewer.deleteAnnotations();
});
}
UnHideAnnotations() {
var viewer = (<any>document.getElementById('pdfViewer')).ej2_instances[0];
viewer.importAnnotation(JSON.parse(this.exportObject));
}
Sample Link:
You can find the full sample in our GitHub repository.
Conclusion:
I hope you enjoyed learning about how to show and hide annotations in the Angular PDF Viewer.
You can refer to Angular PDF feature tour page to know about its other groundbreaking feature representations and documentation , and how to quickly get started for configuration specifications.
You can also explore our Angular PDF Viewer Exampleto understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, BoldDesk Support, or feedback portal. We are always happy to assist you!