Firefox cross origin PDF

Viewed 615

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:

  1. Use window.frames["pdf-iframe"].focus(); window.frames["pdf-iframe"].print();
  2. Enable/disable pdfjs.disabled
  3. 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)
  4. Installed "CORSE" extension in order to remove Cross-Origin
  5. Set security.fileuri.strict_origin_policy as FALSE
  6. Saved the PDF as base64_encode and then used <iframe src="data:application/pdf;base64,my_binary_data"
  7. Added header("Access-Control-Allow-Origin: *");
  8. Installed the latest Firefox version
  9. Changed https://sitename to https://www.sitename
  10. Changed the file path to match the path of the source code. The code is being executed in sitename.com/app/files and the file path is sitename.com/public/pdf-files/mypdf.pdf
  11. Instead of retrieving the file path from PHP, read the file directly using header() and readfile() functions
  12. Tried to use a button to open the iframe instead of auto-load/print
0 Answers
Related