Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS Print pdf file

Tags:

javascript

I try to print pdf file in javaScript. I get the file's url from the server.

var iframe = document.createElement('iframe');
                document.body.appendChild(iframe);

                iframe.style.display = 'none';
                iframe.src = urlBaseImage + 'Report//' + result;
                iframe.focus();
                iframe.contentWindow.print();

But he give me empty page, I checked the url and it is really correct. What Can I do? Thanks!

like image 499
Nom Avatar asked Apr 25 '26 04:04

Nom


1 Answers

You can use this library, Print.js: http://printjs.crabbly.com/

It is very easy to print PDF files with it.

Just pass the PDF file url to the printJS() function;

For example:

printJS('docs/my_pdf_file.pdf');

like image 118
crabbly Avatar answered Apr 27 '26 18:04

crabbly