I have seen lots of topics, but none of the solutions worked.
My app creates a PDF file with PHP and then retrieves the path into JS. After that I create an Iframe and tell the browser to print it.
The following code works only on chrome, but my POS Printer has a issue with chrome (documented) that creates alot of paper. So the solution is to use another browser...so my guess was to use Firefox.
$('#pdf-iframe').attr('src', json.pathToPdf).after(function()
{
setTimeout(function()
{
document.getElementById('pdf-iframe').contentWindow.focus();
document.getElementById('pdf-iframe').contentWindow.print();
}, 300);
});
In google chrome the PDF Preview is opened, in Firefox I receive the following error:
SecurityError: Permission denied to access property "print" on cross-origin object
What I have tried so far without success:
- Use
window.frames["pdf-iframe"].focus();window.frames["pdf-iframe"].print(); - Enable/disable
pdfjs.disabled - Use imagick to convert to PNG (and it works - it allows to print) however the receipt PDF is broken in two pages (the receipt only has one page) AND it add's automatically headers and footers to the img (like the url; pages number; etc)
- Installed "CORSE" extension in order to remove Cross-Origin
- Set
security.fileuri.strict_origin_policyas FALSE - Saved the PDF as
base64_encodeand then used<iframe src="data:application/pdf;base64,my_binary_data" - Added
header("Access-Control-Allow-Origin: *"); - Installed the latest Firefox version
- Changed https://sitename to https://www.sitename
- Changed the file path to match the path of the source code. The code is being executed in
sitename.com/app/filesand the file path issitename.com/public/pdf-files/mypdf.pdf - Instead of retrieving the file path from PHP, read the file directly using
header()andreadfile()functions - Tried to use a button to open the iframe instead of auto-load/print