javascript how to print pdf file through windows.print

Gabriele Rossi 0 Reputation points
2025-05-29T16:00:47.8033333+00:00

inside a aspx file javascript how to print pdf file through windows.print

ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
442 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,631 Reputation points Volunteer Moderator
    2025-05-29T17:44:09.1133333+00:00

    assuming the users browser has pdf support, you can use a hidden iframe and browser print:

    function printPDF(url) {
      const iframe = document.createElement('iframe');
      iframe.style.position = 'fixed';
      iframe.style.right = '100%';
      iframe.style.bottom = '100%';
      iframe.src = url;
      iframe.onload = () => {
        iframe.contentWindow.print();
      };
      document.body.appendChild(iframe);
    }
    

    you can also use the pdf.js library:

    https://github.com/mozilla/pdf.js

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.