I have a project that uses jQuery and I need to print a PDF file that is stored online (Ex. http://www2.hawaii.edu/~freeman/courses/phil360/16.%20Myth%20of%20Sisyphus.pdf). While the print()
function works just fine if the PDF is in the local directory, the print preview is showing blank whenever the iframe's src is a url link.
My iframe:
<iframe id="print-pdf" hidden></iframe>
My jquery:
var ifrm = document.getElementById("print-pdf");
ifrm.src = 'http://www2.hawaii.edu/~freeman/courses/phil360/16.%20Myth%20of%20Sisyphus.pdf';
console.log(ifrm.src);
ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
ifrm.document.open();
ifrm.document.close();
$('#print-pdf').load(function () {
if (navigator.userAgent.indexOf("Firefox") > 0) {
document.getElementById("print-pdf").contentWindow.print();
}
else {
document.getElementById("print-pdf").contentWindow.document.execCommand('print', false, null);
}
);
I haven't found any solution regarding specific problem anywhere so any suggestion/s would be wonderful!