Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print is fuzzy/blurry #2750

Open
BadFriend opened this issue Feb 20, 2013 · 46 comments
Open

Print is fuzzy/blurry #2750

BadFriend opened this issue Feb 20, 2013 · 46 comments

Comments

@BadFriend
Copy link

if i print a pdf with FF19 and the new pdf function the print is blurry.

if i print with acrobat the font is clear.

left= acrobat
right = ff pdf

have you an idea?

https://plus.google.com/105533044232180103026/posts/dYL855pBkSM

@gigaherz
Copy link
Contributor

I'd guess it's because the pdf.js output is a canvas (one canvas per page, to be exact), which probably doesn't match 100% the printer resolution.

@musiphil
Copy link

This happens to me, too.

DSCF8966

  • top = Firefox builtin PDF.js
  • bottom = Adobe Acrobat

The print quality is simply unacceptable.
In addition, the builtin PDF.js generates a black border on the right and bottom sides, just as if it were from photocopying a smaller size sheet.

@BadFriend
Copy link
Author

Any solution? i'm in a hotline and i have 200 users with this problem.

@yurydelendik
Copy link
Contributor

@BadFriend, @musiphil, what operating system you or your users use?

@tombei
Copy link

tombei commented Feb 21, 2013

Same issue here on FFox 19 on WinXP to PostScript printer. The fine horizontal lines are dithered, while the vertical lines are fine. Headers and footers are fine as well.

@musiphil
Copy link

I'm running Firefox 19.0 on Windows 7, and I printed those documents to a HP Color LaserJet CP4525 printer with PCL6.

@BadFriend
Copy link
Author

FF19 + Win7 64bit + OKI561 via PCL6 on WSD Port or Adobe PDF (Adobe Acrobat 9.2.0)

IMG_20130222_074757

left: Chrome Plugin
middle: Adobe Reader
right: Firefox pdf.js

Download PDF -> http://www.file-upload.net/download-7241349/offers-36.pdf.html

@jviereck
Copy link
Contributor

See also #2771. Quoting @brendandahl:

The low quality is being tracked in https://bugzilla.mozilla.org/show_bug.cgi?id=811002 .

@timvandermeij
Copy link
Contributor

The upstream bug has been fixed. Is this still an issue with the latest versions of Firefox and PDF.js?

@jviereck
Copy link
Contributor

jviereck commented Nov 3, 2013

The upstream bug has been fixed. Is this still an issue with the latest versions of Firefox and PDF.js?

I think it was only fixed for Windows. There is a new bug filled for OSX (bug 932313) but I am not convinced it is valid (see my comment at https://bugzilla.mozilla.org/show_bug.cgi?id=932313#c2).

Until the issue is not fixed on Linux, I vote for keeping this bug open.

@jonny64
Copy link

jonny64 commented Feb 16, 2015

Is it fixed?
This demo page prints ok from firefox
http://mozilla.github.io/pdf.js/web/viewer.html
https://dl.dropboxusercontent.com/u/1383480/work/printing/2015-02-16%2011.29.52.jpg

from Chrome and Chromium print result is SO blurry, I can't find words to describe it
https://dl.dropboxusercontent.com/u/1383480/work/printing/2015-02-16%2011.29.58.jpg
I tried to set dpi for printer and PRINT_SCALE RATIO to 1, 3, 4, 8 - no effect
I tried latest version from github (8614c17) - same
(enviroment: Chrome, Chromium, windows 7)

Am I missing something?
Could you please review this and possibly suggest quick workaround?

@jviereck
Copy link
Contributor

@jonny64 thanks for reporting this! Unfortinate, I guess there is not much that can be done for Chrome/Chromium here. The better print quality in Firefox results by using a special API for printing that is available in Firefox but not in Chrome. Back in the days I proposed the API as a standard but there was not much interest and therefore it is still only available in Firefox.

@jonny64
Copy link

jonny64 commented Feb 16, 2015

:) @jviereck, well, ok, I should live with it
I tried Chrome internal viewer
It prints ok, but it's 'Save' brokes kiosk mode
(we need to print with preview from Chrome in kiosk fullscreen mode)

Fortunatly, I have some backgound with C some time ago
https://pdfium.googlesource.com/pdfium.git
Is it correct source for Chrome internal viewer?
Is it better to hide 'Save' from Chrome settings or when --kiosk command line is set?
Do you have any high level ideas where and how can I implement it?

@dahjelle
Copy link

dahjelle commented May 8, 2015

This is still a bug on OS X and the latest Firefox Dev Edition, as far as I can tell, at least in some circumstances.

How to reproduce without a printer:

  • Click "Print" in the PDF.js viewer.
  • Click the "PDF" button.
  • Choose "Save as PostScript…" (not "Save as PDF…")
  • Open the saved .ps file in Preview.app.

Text is not selectable and, zooming in, the text is quite pixelated. Text looks great if you chose "Save as PDF…"

@a0preetham
Copy link
Contributor

I tried increasing the default resolution in
web/app.js::beforePrint
<< var pageSize = this.pdfViewer.getPageView(0).pdfPage.getViewport(1);

var pageSize = this.pdfViewer.getPageView(0).pdfPage.getViewport(2);

and web/pdf_page_view.js::beforePrint
<< var viewport = pdfPage.getViewport(1);

var viewport = pdfPage.getViewport(2);

Printing is slower but quality has improved

@yurydelendik
Copy link
Contributor

Some improvements after #7677

@jeff-griffin-hm
Copy link

Have there been any updates to this issue in the past 4 months? This is still noticeable on the latest version of pdf.js. I recently rolled out a deployment using pdf.js and now have documents printing with a fuzzy letters that weren't a problem with Chrome's native PDF reader.

You can reproduce this issue by printing from Mozilla's own demo page. I know it isn't a driver issue because it happens when you print to a PDF as well.

It looks like some people using pdf.js in production have had to bypass pdf.js entirely to work around this issue (example).

@timvandermeij
Copy link
Contributor

timvandermeij commented Feb 23, 2017

Currently, higher quality printing is not possible without greatly increasing memory usage, which most browsers won't take well. The canvas back-end cannot provide such functionality. There is a project open (https://github.com/mozilla/pdf.js/projects) to research using the prototype SVG back-end for high quality printing.

@stephenross
Copy link

I have found the PDF.js has had acceptable print quality and fuzzy print quality depending on the version of Firefox installed so would like to take a look at what has changed between the versions I was able to print from. I have https://imgur.com/7Beh7MO, which is output from a direct print from left to right of Firefox 52, 47.0.2, and 42, with the first two at least being fresh updates. As shown, something changed in PDF.js between FF 47.0.2 and FF 52 releases that seems to have crapped up the quality, so if anyone has info on what bookmarks to look at to start with for those versions of Firefox, I wouldn't mind taking a look to start.

@stephenross
Copy link

Looking at the Firefox repository versions of PDF.js, I see that 47.0.2 was version 1.4.121, which corresponds to commit 51f6aba (might be the commit after, which is be1e12d) and that Firefox 52 shipped with PDF.js 1.6.315, which is roughly commit c23f124. I am currently looking into diffing these commits, but the difference between them is probably 400 commits and any information on where printing lies would be very helpful.

@Snuffleupagus
Copy link
Collaborator

As shown, something changed in PDF.js between FF 47.0.2 and FF 52 releases that seems to have crapped up the quality,

While it's certainly possible that a change in PDF.js is responsible, I wouldn't (at least initially) entirely discount the possibility that the issue could be related to e.g. graphics/printing code in other parts of Firefox.
It may be helpful, and perhaps even quicker, to use http://mozilla.github.io/mozregression/ to try and find a regression range.

@stephenross
Copy link

stephenross commented Mar 14, 2017 via email

@timvandermeij
Copy link
Contributor

timvandermeij commented Mar 14, 2017

Previously, we used the Mozilla-specific mozPrintCallback wherever we could if it was supported, i.e., in add-on and non-add-on versions in the Firefox browser, as it presumably allowed us to print with less memory consumption and higher quality. However, we tried to reduce the usage of that because it's Firefox-specific and sometimes buggy, so now we only use it in the Firefox add-on (https://github.com/mozilla/pdf.js/blob/master/web/firefox_print_service.js).

In general, we now render the canvases and print them using the regular browser-defined printing logic, so I think the issue may either be in changed canvas scaling/font rendering code or a browser bug.

Refer to c09f634 for the majority of that change. You might want to check if there is a difference in printing quality from Firefox with and without the add-on.

@mpryvkin
Copy link

mpryvkin commented Mar 4, 2018

Since c09f634 there is now renderPage function in web/viewer.js and print resolution is hard-coded in there as 150 DPI.

function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size) {
  var scratchCanvas = activeService.scratchCanvas;
  var PRINT_RESOLUTION = 150;
  var PRINT_UNITS = PRINT_RESOLUTION / 72.0;

To change print resolution to 300 DPI, simply change the line below.

var PRINT_RESOLUTION = 300;

According to the release tags, all PDF.js versions from 1.7.x to 1.10.x should have that ability now. I am surprised this is not documented anywhere.

Ideally there should be ability to change print resolution from query parameters instead of modifying web/viewer.js.

See How to increase print quality of PDF file with PDF.js viewer for more details.

@johannish
Copy link

If @mpryvkin's fix is legitimate, this should definitely be exposed as an option in about:config.

@mpryvkin
Copy link

mpryvkin commented May 28, 2019

@timvandermeij Thank you and @kleins05 for this improvement. I have updated my post regarding this feature.

Am I correct in assuming that with this update print resolution can be set using the code below?

document.addEventListener('webviewerloaded', function() {
  PDFViewerApplicationOptions.set('printResolution', 300);
});

@timvandermeij
Copy link
Contributor

timvandermeij commented May 28, 2019

Yes, I think you're correct. The webviewerloaded event is indeed the right event to listen to for setting app options; see:

pdf.js/web/viewer.js

Lines 208 to 210 in c91f437

// Give custom implementations of the default viewer a simpler way to
// set various `AppOptions`, by dispatching an event once all viewer
// files are loaded but *before* the viewer initialization has run.

After that point PDFViewerApplicationOptions should always be available. I haven't tried this particular snippet, but from inspection it looks good and you can try it out by checking out the latest master branch code, adding that snippet and checking if the print quality improves.

@johannish
Copy link

@raztus Yes, I meant users of the library. Firefox builds were left out of that scope (#10854 (comment)) because it's not easy to tell what happens with e.g., browser responsiveness and memory usage if you increase this value. If we get more feedback on that, I'm not against considering making the preference available for Firefox (mozcentral) builds as well.

@timvandermeij I would love to help provide some of that feedback. After all, about:config is already a warranty-voiding area ;) How can I contribute? Would I need to build Firefox from scratch to change the printResolution?

@timvandermeij
Copy link
Contributor

timvandermeij commented May 29, 2019

You can experiment with this by opening the default viewer (either https://mozilla.github.io/pdf.js/web/viewer.html which always runs the most recent master branch code or a custom checkout), opening the web console and entering PDFViewerApplicationOptions.set('printResolution', 300);. That will set the print resolution to 300 DPI instead of the default 150 DPI. If you then click the print button, you'll notice a difference in print quality, but also in time it takes to render the pages and memory consumption (I just tried this myself to make sure these steps work). The main question is how the print resolution in DPI relates to memory usage/rendering time for various types of PDF files, such as small/medium/large size but also text-only or image-heavy documents. If we know more about how it behaves in various real-life scenarios, we might be able to introduce the setting for Firefox builds too and/or update the default value.

@qwer1304
Copy link

qwer1304 commented Jun 9, 2019

I tried the above method, but I'm getting undefined.
This is with Chrome Canary Version 77.0.3818.0 (Official Build) canary (64-bit)

@timvandermeij
Copy link
Contributor

Yes, running that will give undefined because setting an option has no return value, but if you then print again you'll have increased print output quality.

@qwer1304
Copy link

qwer1304 commented Jun 9, 2019

Thx.
Why isn't this available as a user settable option but only as a programmatically settable one?

@timvandermeij
Copy link
Contributor

This is explained in the comments above, in particular #2750 (comment). We first want to experiment with it before we make it more easily accessible. Note that just a day ago PR #10879 was merged with should help a bit with the memory usage issue, and now that this is at least programmatically settable, we can more easily experiment with it and include improvements.

@marco-c marco-c changed the title Print is fuzzy/blurry Print is fuzzy/blurry https://github.com/mozilla/pdf.js/issues/14277 Feb 24, 2022
@marco-c marco-c changed the title Print is fuzzy/blurry https://github.com/mozilla/pdf.js/issues/14277 Print is fuzzy/blurry Feb 24, 2022
@marco-c marco-c changed the title Print is fuzzy/blurry Print is fuzzy/blurry - Feb 24, 2022
@marco-c marco-c changed the title Print is fuzzy/blurry - Print is fuzzy/blurry - [Bug 1269023 - poor print quality from pdf](https://bugzilla.mozilla.org/show_bug.cgi?id=1269023) Feb 24, 2022
@marco-c marco-c changed the title Print is fuzzy/blurry - [Bug 1269023 - poor print quality from pdf](https://bugzilla.mozilla.org/show_bug.cgi?id=1269023) Print is fuzzy/blurry Feb 24, 2022
@marco-c
Copy link
Contributor

marco-c commented Jul 6, 2022

We should take a look at all the PDFs here and in linked issues and see if the blurriness would be fixed by https://bugzilla.mozilla.org/show_bug.cgi?id=1774615.

@thomaskeefe
Copy link

Here is another example: USPS label printed from Firefox PDF.js on the left, and printed with MacOS Preview on the right. PDF.js totally mangled the barcodes. There is no way Firefox can be considered a first-class browser with this issue.

IMG_0851

@marco-c
Copy link
Contributor

marco-c commented Sep 2, 2022

@thomaskeefe could you upload the original PDF? (you can remove the private info)

@Snuffleupagus
Copy link
Collaborator

If #2750 (comment) is on a Mac, then it could be another case of bug 1779202.

@thomaskeefe
Copy link

@marco-c Attached is the PDF with PII redacted. After redacting, I printed it again with Firefox PDF.js as a check; the barcodes were still mangled. @Snuffleupagus yes I am using a Mac.

ebay-label.pdf

@robmv
Copy link

robmv commented Dec 9, 2022

Let me give the following suggestion to increase the print quality, at least on Mac and modern Linux clients when PDF.js is running embedded in Firefox and not as a library.

PDF.js already load the internal representation of the PDF so it would not be impossible to extract the content of the original pages selected for printing and generate a new PDF scaled and rotated to the output page size and orientation. When that PDF is ready, it can be submitted natively as a PDF to the local IPP Server, currently macOS and Linux use CUPS as the IPP frontend to all printer.

I know this works because this is what I do on Linux for an internally developed PDF viewer for Java based on pdfium. Instead of sending rendered images to the printer, I use the pdfium API to generate a new PDF, rotate and scale the pages and add the user selected pages to the new PDF. After that I use Java Print Service API to get printers that understand PDF natively, that on modern Linux are all, because CUPS is the IPP frontend for them.

Firefox on Linux already link in some way with CUPS for printing, so adding a internal API to submit the generated PDF is possible, if it doesn't already exist.

@hmilas
Copy link

hmilas commented Jan 20, 2023

Copying my post from Closed #15933

Hi @Snuffleupagus, I'm not sure if I understand correctly.
Is there currently a bug within pdf.js or Firefox or there is some workaround?

I have tried setting printResolution option in Chrome console for my document in https://mozilla.github.io/pdf.js/web/viewer.html, as instructed in #2750 (comment), for example: PDFViewerApplicationOptions.set('printResolution', 300)

but the blurry still persists when printing (I have tried multiple resolutions: 300, 600 and 1200; also 60 to confirm that the property is applied through Chrome Console)

@insinfo
Copy link

insinfo commented Oct 31, 2023

Why is it that when you open a PDF file in Firefox, click on the print icon, it prints the PDF correctly without converting it to a Bitmap image, but when you use the PDF viewer in PDF.js, it prints as an image?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: High priority
Development

No branches or pull requests