DEV Community

John Au-Yeung
John Au-Yeung

Posted on • Originally published at thewebdev.info

3

How to send a PDF file directly to the printer using JavaScript?

To send a PDF file directly to the printer using JavaScript, we create an object URL.

For instance, we write

const dataUrl = window.URL.createObjectURL(file);
const pdfWindow = window.open(dataUrl);
pdfWindow.print();
Enter fullscreen mode Exit fullscreen mode

to call createObjectURL with the PDF file to create the PDF file object URL string.

Then we open the dataUrl in a window wiith window.open.

Finally, we call print to open the print dialog to print the PDF.

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More