html - Options having no impact on View of ng2-pdfjs-viewer - Stack Overflow

admin2025-04-23  5

I'm updating my Angular App to Angular 19 and with that I had to switch vom ng2-pdfjs-viewer to @kariudo/ng2-pdfjs-viewer because the original one doesn't support Angular 19 yet.

This is my code:

<ng2-pdfjs-viewer [pdfSrc]="source" 
                  [download]="false"
                  [fullScreen]="false"
                  [find]="false"
                  [viewBookmark]="false"
                  [openFile]="false"
                  [print]="false"
                  [zoom]="'page-width'"
                  [useOnlyCssZoom]="true"
                  [page]="page"
                  ></ng2-pdfjs-viewer>

The Viewer is working and is showing the right PDF, but somehow the Options I set, like disabling the download button, are not working.

What am I doing wrong?

I'm updating my Angular App to Angular 19 and with that I had to switch vom ng2-pdfjs-viewer to @kariudo/ng2-pdfjs-viewer because the original one doesn't support Angular 19 yet.

This is my code:

<ng2-pdfjs-viewer [pdfSrc]="source" 
                  [download]="false"
                  [fullScreen]="false"
                  [find]="false"
                  [viewBookmark]="false"
                  [openFile]="false"
                  [print]="false"
                  [zoom]="'page-width'"
                  [useOnlyCssZoom]="true"
                  [page]="page"
                  ></ng2-pdfjs-viewer>

The Viewer is working and is showing the right PDF, but somehow the Options I set, like disabling the download button, are not working.

What am I doing wrong?

Share Improve this question edited Jan 20 at 14:49 Marrome asked Jan 20 at 10:20 MarromeMarrome 111 silver badge5 bronze badges 1
  • 1 Then how come with Angular 18 and the original ng2-pdfjs-viewer the download and print buttons are not visible, as declared by the options? Screenshot: i.sstatic.net/oTttkUXA.png – Marrome Commented Jan 20 at 14:47
Add a comment  | 

1 Answer 1

Reset to default 0

I had the same problem. It seems that the options are not being passed on correctly/completely. I already tried it with the older version 17.0.21 of @kariudo/ng2-pdfjs-viewer and also the example from the GitHub repo didn't work.

So I used this rather less nice workaround: workAroundDisableButtons should be called when the PDF is loaded and rendered.

//.html
  <ng2-pdfjs-viewer [pdfSrc]="url" #viewer></ng2-pdfjs-viewer>

//.ts
  @ViewChild('viewer') pdfViewer: PdfJsViewerComponent;
  get viewerAppconfig() {
    return this.pdfViewer.PDFViewerApplication.appConfig;
  }

  workAroundDisableButtons() {
    (this.viewerAppconfig.secondaryToolbar.printButton as HTMLElement).style.display = 'none';
    (this.viewerAppconfig.secondaryToolbar.downloadButton as HTMLElement).style.display = 'none';
    (this.viewerAppconfig.secondaryToolbar.openFileButton as HTMLElement).style.display = 'none';
    (this.viewerAppconfig.secondaryToolbar.presentationModeButton as HTMLElement).style.display = 'none';
  }
转载请注明原文地址:http://anycun.com/QandA/1745377480a90642.html