Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening and printing large files in javascript

I am trying to open a local pdf file and print it.It works for files upto 5 kb,but it takes time to load for big files within 1000ms and hangs.I want it to be dynamic and need not fix the timeout . I tried window.onload but it does not work.Also i dont want to add any onload event to the printing page.

Is there a efficient solution

var win=window.open(printUrl);
setTimeout(function() {
        win.print();
        win.close();
        }, 1000);
like image 205
geekops Avatar asked May 24 '26 03:05

geekops


1 Answers

Found an workaround for this.Have used PDF Javascripts and embedded a Javascript to print the file.This makes sure that the file is only printed once the page has been loaded.

I had used PDFbox to parse PDF contents and added the below:

PDActionJavaScript javascript = new PDActionJavaScript("this.print();");
like image 198
geekops Avatar answered May 26 '26 22:05

geekops



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!