Concealing the print option while utilizing PDFObject in conjunction with PDF.js

When displaying a file using pdf.js, I encountered issues with the print button and other functionalities. I was able to hide the buttons using CSS for Chrome, but not for Internet Explorer, where I had to resort to using JavaScript. While the JavaScript solution worked for loading one file, subsequent files still displayed the buttons.

viewer.html

<script type="text/javascript">
    $(function () {

        $('#print').hide();
        $('#viewBookmark').hide();
        $('#openFile').hide();
    });
</script>

viewer.css

button#openFile, button#print, a#viewBookmark {
        display: none;
    }

default.cshtml

$('.file').on('click touchend', function (e) {
        e.preventDefault();
        if ($(this).hasClass('disabled'))
            return;
        var path = $(this).data('path').replace("\\\\", "http://").replace("@pdfFolder", "Uploads");
        var name = $(this).data('name');
        var lastname = $(this).data('lastname');
        name = name.length > 8 ?
            name.substring(0, 5) + '...' :
            name.substring(0, 8);
        lastname = lastname.length > 8 ?
            lastname.substring(0, 5) + '...' :
            lastname.substring(0, 8);
        var tabCount = $('#tabs li').size();
        var uuid = guid();
        $(this).attr('data-position', uuid);
        $('#content').css('display', 'block');
        if (tabCount === 5) {
            $('#maximumTabsModal').modal('show');
        } else {
            $(this).addClass('disabled')
            $('<li role="presentation" data-position="' + uuid + '"><a href="#panel' + uuid + '" aria-controls="panel"' + uuid + ' role="tab" data-toggle="tab">' + name + '<span class="close"></span><br/>' + lastname + '</a></li>').appendTo('#tabs');
            $('<div class="tab-pane" id="panel' + uuid + '"><div id="pdf' + uuid + '" class="pdf"></div></div>').appendTo('.tab-content');
            $('#tabs a:last').tab('show');
            var options = {
                //pdfOpenParams: {
                //    view: "FitV"
                //},
                forcePDFJS: true,
                PDFJS_URL: "pdfjs/web/viewer.html"
            };
            var pdf = PDFObject.embed(path, '#pdf' + uuid, options);
            $('#print').hide();
            $('#viewBookmark').hide();
            $('#openFile').hide();
            $('#exd-logo').hide();
        }
    });

Answer №1

Regrettably, PDFObject does not have the capability to hide the print button. It solely offers a mechanism for specifying PDF Open Parameters, which do not include the feature to hide the print button.

While I may not be well-versed in PDF.js, considering it is all JS-based and hosted on your domain, you should have full script access to potentially find a way to manipulate it and remove the print button. Best of luck on your endeavor!

Answer №2

By utilizing the pagerendered event provided by PDF.js, I successfully managed to hide the buttons.

viewer.html

<script type="text/javascript">
    $(function () {
        document.addEventListener("pagerendered", function (e) {
            $('#print').hide();
            $('#viewBookmark').hide();
            $('#openFile').hide();
        });
    });
</script>

Answer №3

I am taking a shot in the dark here because I am uncertain if the PDF viewer loads within an <iframe> or not. However, the code below will continuously scan the page and hide the print button if it finds it.

    var $printSearch = setInterval(function() {
      if ($('#print').length > 0 || $('#print').is(':visible')) {
        hidePrint();
      } else {
        //doNothing
        console.log('Searching...');
      }
    }, 150);

    function hidePrint() {
      $('div#print').css('display', 'none');
    }

If it does appear in an iframe, we might be able to utilize the jQuery methods .contents() and filter() to target those hard-to-find buttons.

Answer №4

Have you experimented with CSS print stylesheets?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Showing various information in tab form depending on a specified variable

In my current project, I am developing a user-friendly view that allows users to easily switch between different sets of data. The specific scenario involves a manager overseeing multiple stores with various franchises. Our dashboard presents aggregated re ...

Split up the author page description with a new line break for better readability on WordPress

I have a unique plugin that transforms the Biographical Info editor into a standard editor interface. However, I am facing an issue where line breaks/new rows created in the backend are not visible on the front end, and I'm unsure of where the problem ...

Connecting Vue.JS page to my existing HTML page: A step-by-step guide

While developing my website, I faced a challenge with the structure. The home page was built using traditional HTML/CSS, while the other pages were created in Vue.js. Is there a method to connect these two different types of files? For instance, can I inc ...

Transforming DOM elements into Objects

Here are some values that I have: <input name="Document[0][category]" value="12" type="text"> <input name="Document[0][filename]" value="abca.png" type="text" > I am looking for a way to convert them into an object using JavaScript or jQuer ...

Mastering the art of changing text color based on element class name in CSS3

Is it possible to dynamically set the text color of a list item based on the class name of its nested span element? For example, if the span has a class of "green", the text color of the parent li should also be green. How can this be achieved? Demo:https ...

Unable to fetch source for HTML img tag

I am struggling with using jQuery to retrieve the src attribute of an image when it is clicked. Unfortunately, my current code does not output anything to the console and returns undefined when I try to manipulate it in the browser console. I do not have m ...

Encountering a 403 error when attempting to upload files from Angular to a Micron

I have encountered an issue while attempting to upload multiple files to the Micronaut Rest API. The uploading process works seamlessly with Postman and Swagger in the Micronaut Rest API, but when using the Angular app, the POST method throws a 403 HTTP er ...

Trigger form submission with validation using jQuery

How can I redirect a user to another page named "free.php" from the index page without changing the URL, using jQuery? Below is an example I have created: http://jsfiddle.net/jKHQe/ The checkbox validation works in the example, but I am unable to redir ...

Creating an HTML table with collapsed borders and hidden rows/columns using the `border-collapse

I am facing a situation where I have a table with multiple lines as shown below: <table> <tr id="line1"><td>Line</td><td>1</td></tr> <tr id="line2"><td>Line</td><td>2</td></t ...

How can I achieve an endless scrolling text effect within a square on a webpage using CSS?

My header currently displays a horizontal infinite scroll of text, but I am looking to achieve a square pattern wrapping around the page. Can you provide guidance on how this can be accomplished? Below is the code snippet I am working with: .marquee { ...

Issue with form validation causing state value to remain stagnant

Giving my code a closer look, here is a snippet in HTML: <input type="text" name="email" id="email" autoComplete="email" onChange={(e) => {validateField(e.target)}} className="mt-1 ...

What is the best way to horizontally align three animated progress bars alongside images?

Check out this jsfiddle that shows a vertical alignment of the progress bars. How can I modify it to align them horizontally and centered? https://jsfiddle.net/bLe0jLar/ .wrapper { width: 100px; height: 100px; } .wrapper > #bar, #bar2, #bar3 { ...

Issue with Firebase V9 addDoc: No indication of success or failure, and data is not being written to the

I am encountering an issue where the authentication related functions are working fine, but I am unable to make any progress with Firestore. Despite no errors or successes being returned by the try-catch block, nothing seems to happen in the Firestore data ...

Ensure Next.js retains the route when moving from one screen to another

I am currently facing a challenge in Next.js while creating a Dashboard. The root route for this dashboard would be: /dashboard/ Within this route, users can select different stores to access their respective dashboards. When a user clicks on a specific s ...

Is the process.env.NODE_ENV automatically set to 'production'?

While examining someone else's code, I noticed this particular line. if (process.env.NODE_ENV === 'production') { ... The application in question is a node.js app with express server and reactjs front-end. If we were to deploy it on Heroku ...

Using AngularJS to prevent HTML injection in input fields

Is there an effective method to prevent HTML injection in input fields? As an example, if I have a search input field: <input id="search" type="text" ng-model="search" placeholder="search..."> I want to ensure that any attempts to input malicious c ...

Failure [ERR_STREAM_WRITE_AFTER_END]: writing past the endpoint [npm-request using socket.io]

My server has a socket server running, and on my laptop, I have a socket.io-client service. When both are turned on, they establish a connection. When other users request information from my server, the server sends that request to my laptop via a socket. ...

Selection tool for Material UI Fields

Is there a way to design something similar to this layout using Material UI? I'm looking to create a selection between fields. Any advice on how to achieve this in Material UI? ...

Why am I experiencing varying outcomes between createShadowRoot and attachShadow methods?

Recently, I've encountered an issue related to shadow dom while working on a project. After referring to an older tutorial that uses createshadowroot, I realized that this method is now considered deprecated and should be replaced by attachshadow. Un ...

What's the best way to display a bootstrap modal window popup without redirecting to a new page?

I am having trouble implementing a modal window that will display validation errors to the user when they submit a form. Currently, the window is opening as a new view instead of overlapping the existing form's view. How can I adjust my code so that t ...