stephanrauh / ngx-extended-pdf-viewer

A full-blown PDF viewer for Angular 16, 17, and beyond
https://pdfviewer.net
Apache License 2.0
449 stars 167 forks source link

I have pdf with annotations. Are there an option to show/hide them? #2359

Closed NazarKalytiuk closed 3 weeks ago

NazarKalytiuk commented 3 weeks ago

In Google Chrome default viewer there is a button show/hide annotations.

image

In the library these annotations render, but I didn't find how to hide them or get as JSON etc.

I added an annotation with the macos books app. pdfsample annorated.pdf

stephanrauh commented 3 weeks ago

OK. Let me ponder about it. The idea of hiding annotation is new to me, so I'd like to think about it.

As for exporting the annotations: Does NgxExtendedPdfViewerService.getSerializedAnnotations() do the trick for you?

NazarKalytiuk commented 3 weeks ago

Does NgxExtendedPdfViewerService.getSerializedAnnotations() do the trick for you? - No, it returns only annotations made with the library. I want this primary to be able to download files with and without annotations. And it is preferable to use native annotations.

stephanrauh commented 3 weeks ago

You can simply hide the annotations with CSS:

.annotationEditorLayer, .annotationLayer {
    display: none;
}

Of course, that doesn't remove the annotations from the PDF file, it only hides them from the user.

To remove the annotations entirely, you have to access a low-level API:

const PDFViewerApplication: IPDFViewerApplication = (window as any).PDFViewerApplication;

if (!PDFViewerApplication?.pdfDocument?.annotationStorage) {
   ... // remove everything from the annotationStorage hash table
}

Note that probably changing the annotationStorage doesn't re-render the page.

stephanrauh commented 3 weeks ago

BTW, if you only want to remove editor annotions, you can use pdfViewerService.removeEditorAnnotations(), as shown on https://pdfviewer.net/extended-pdf-viewer/export-annotations.

stephanrauh commented 3 weeks ago

I've just seen that you can't remove annotations that were already stored in the document. You can only remove annotations that have been added after loading the document.