2

I am using primefaces documentViewer which is based on mozilla PDF.js: 2.11.338

https://www.primefaces.org/showcase-ext/views/documentViewer.jsf

and I want to customize the viewer to control which buttons to appear in the toolbar like rotate & print & download only.

I couldn't find any guides about that in primefaces website.

Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498

1 Answers1

2

There is no JS Widget for Document Viewer however this can be accomplished easily with a JS function like this.

Note: Some buttons like presentationMode are special and need to be hidden a little differently.

pdfHideButtons : function() {
    var pdfViewer = $("#YourDivId");
    if (pdfViewer) {
        $(pdfViewer.contents().find("#openFile")).hide();
        $(pdfViewer.contents().find("#viewBookmark")).hide();
    }
}

Then on your page add this code to basically hide the buttons after the page loads.

<script>
        $(document).ready(function() {
            setTimeout(function(){ pdfHideButtons(); }, 1000);
        });
</script>
Melloware
  • 10,435
  • 2
  • 32
  • 62
  • I tried your solution but adding your pdfHideButtons JS code results in `Uncaught SyntaxError: Functions statements require a function name`. So I changed it to `function pdfHideButtons() { ... }` and added your 2nd JS code to my page. These results to `Uncaught TypeError: $ is not a function` in `pdfviewer.html.xhtml:403` ( `$(document).ready(function () { ... );` – raho Sep 15 '22 at 08:03
  • The `Uncaught TypeError` disappears, when adding the call to `pdfHideButtons()` at the end of my page. Nevertheless `window.frames[0].PDFViewerApplication` results in `pdfViewer undefined` – raho Sep 15 '22 at 08:16
  • I updated my answer you have to find the PDF Viewer main DIV ID and use Jquery like above – Melloware Sep 16 '22 at 13:45