crabbly / Print.js

A tiny javascript library to help printing from the web.
MIT License
4.28k stars 672 forks source link

Issue printing PDF using Firefox #695

Open bababash opened 10 months ago

bababash commented 10 months ago

Hello Print.js team, I'd like to report an I am experiencing using Firefox. This is working perfectly in Chrome

Implementation:

<button type="button" onclick="printJS('/static/test.pdf')">Print</button> test.pdf was copied from this repository Using Print.js v1.6.0 Using Firefox v118.0.2 (64-bit)

Issue:

Upon clicking the button, I get the following output in my console

Warning: Invalid absolute docBaseUrl: "blob:http://127.0.0.1:8000/ff77f293-d166-45ff-a02a-d3e4c7852f7a".

(pdf.worker.js:970:13)

Warning: Bad value, for custom key "AAPL:Keywords", in Info: .

(pdf.worker.js:970:13)

PDF 8eed11de459c2ed35fec410bf057a870 [1.3 Mac OS X 10.11.4 Quartz PDFContext / Word] (PDF.js: 3.10.86 [c72cb5436])

(viewer.js:1518:13)

Uncaught NS_ERROR_FAILURE:

([print.min.js:1:4198])

Hope you can help me!

bababash commented 10 months ago

I also tried using https://www.npmjs.com/package/print-js-updated which resulted in the same error.

Using the version from the CDN https://printjs-4de6.kxcdn.com/print.min.js opens the PDF viewer on Firefox without throwing an error (doesn't print though)

SaschaAusUlm commented 10 months ago

Seeing the same:

Warning: Invalid absolute docBaseUrl: "blob:https://xxxxxxxxxxxxxxxxxxxxxxx/126c4566-4c9b-4923-a0a4-ec4aff6591c0". pdf.worker.js:970:13 PDF 816648aa36057888347bf1df09e19bd1 [1.4 Skia/PDF m79 / Chromium] (PDF.js: 3.10.86 [c72cb5436])

I see the PDF in my UI, but when I print it's just a blank page and the preview is also white.

It works fine in Edge and Chrome.

Firefox: Version 118.0.2 (64-Bit)

SaschaAusUlm commented 10 months ago

I am seeing that there was a fix committed 8 months ago:

Merge pull request https://github.com/crabbly/Print.js/pull/657 from amoilanen/fix-firefox-110-pdf-printing

but no release was done?

SaschaAusUlm commented 10 months ago

I tried print-js-updated which includes the made but unreleased fix and with that, it works again for me. Sad that this project is going to waste.

bababash commented 10 months ago

Thanks @SaschaAusUlm I'll try again. How did you implement it?

SaschaAusUlm commented 10 months ago

Hey @bababash,

for us, printing is just a one-liner:

public printReport(): void { printJS({ printable: this.selectedReport.downloadUri, type: 'pdf', showModal: true }); }

with printable being a link to one of our PDFs in one of our Blob storages. To make it work again in Firefox, I just had to pull in the patched library with npm and adjust the import.

wmadam commented 10 months ago

Hello, I patched the library with the code from the PR, but I still get a blank page in firefox v119.0 when printing (no errors in console though). Can anyone reproduce this issue or is there an alternative fix?

lucasjuna commented 9 months ago

I've installed print-js-updated Then used import printJS from "print-js-updated"; And it's working in latest version of Firefox. But don`t remove print-js.

bababash commented 8 months ago

Hey @bababash,

for us, printing is just a one-liner:

public printReport(): void { printJS({ printable: this.selectedReport.downloadUri, type: 'pdf', showModal: true }); }

with printable being a link to one of our PDFs in one of our Blob storages. To make it work again in Firefox, I just had to pull in the patched library with npm and adjust the import.

I tried again with print-js-updated from npm. It appears to have the changes merged in but hard to tell. How come there is a disconnect between npm and github?

The issue still exists with Firefox. Works perfectly in Chrome. From Firefox console:

Source map error: Error: request failed with status 404
Resource URL: "path to printjs"
Source Map URL: print.map

Warning: Invalid absolute docBaseUrl: "blob:http://127.0.0.1:8000/6f9819a6-0357-4486-b648-38dcf047f33c". pdf.worker.mjs:339:13
PDF 8e4fcce84c89827e7d1aa79671646b36 [1.3 pypdf / -] (PDF.js: 4.0.67 [5c45dfa0a]) viewer.mjs:10800:13
Uncaught NS_ERROR_FAILURE: print_updated.js:1:4694
bababash commented 8 months ago

If anyone else is hunting for a solution, this is what worked for me to print a pdf in chrome/firefox: https://gist.github.com/timdown/cfacd32f6b5e439bb02aaf142343ce4c

mdodge-ecgrow commented 6 months ago

I'm also having this same issue. It seems to work intermittently in Firefox which is baffling.

Nevermind, I was able to get it working with print-js-updated. Thanks!