10

Today I encountered one weird bug in Chrome's printing behavior. When I try to print a dynamically created PDF using Chrome (also in Firefox), every image inside the PDF gets a little bit smaller (8mm). This doesn't happen neither in Adobe Reader/Acrobat/MacOSX Default Printer Dialog.

Let me explain more about my code so far:

dynamic PDF:

I use prawn to dynamically create a PDF A4 (landscape format) using this code:

require 'prawn'
require "prawn/measurement_extensions"

class CustomPdf < Prawn::Document

  def initialize(label) # A4
    super({
       :page_size =>  "A4", 
       :page_layout => :landscape, 
       :margin => 0, 
       :print_scaling => :none})

    image "my_image.png", :width => 213.mm, :at => [3.mm, 3.mm]
  end
end

nested image inside the PDF:

The Image nested inside the PDF has a size of 213mm x 70mm with 300 DPI. In Pixel: 2515x827.

I create the Image using RMagick but the size, dpi and everything so far seems to be alright. So no further explanation at the moment.

Expected result:

The printed PDF will show an image with 213cm width.

Actual result:

The printed PDF will show an image with 205mm width.

What I tried so far

  • Setting the prawn page_size to something lower than A4 (since the Image isn't bigger as A4 as well...).
  • Playing around with print_scaling(there are 3 modes, :none, :AppDefault, :something_except_the_other_ones (Read more about it here)
  • Giving the image a fixed height (70mm)
  • Playing around with various settings provided by the Chrome Printer Dialog
  • Tested under Windows Chrome (it's 213mm there, weird), maybe it's related to MacOSX Chrome?
  • Tested under IE11 (205mm) unfortunately.

Neither of these did anything. I looked through the Bugreporters of Chromium and found 2 people who might share the same problem as I do:

The last one was touched 2013 but no one said anything that actually worked for my case.


Examples

Here is an example 300 DPI image which width is 2515 px: Example Image If Imgur changes the resolution to 72, you can pull the example image from the repository (link: https://github.com/posixpascal/chrome-printing-bug/blob/master/example.png)

Here is an example PDF

Direct Link: Direct Link

GitHub PDF Viewer: https://github.com/posixpascal/chrome-printing-bug/blob/master/output.pdf


Github Repository with example image & pdf generator script https://github.com/posixpascal/chrome-printing-bug

Unfortunately I can't change the width of the image (not even a pixel). Someone experienced the same problem?

Any ideas? It's an interesting puzzle I guess... :x


When I print a plain image or a website with Chrome there is a 'Use Original Size' or '100% size' option which I don't have when printing the PDF.

I also tried making a webpage instead of a PDF and set the image width to 213mm which didn't work either...

posixpascal
  • 3,031
  • 3
  • 25
  • 44
  • Come on, why doesn't get this any attention, am I missing some critical data? Can one of you at least reproduce it so I'm sure it's not my printer or os that's causing this error? – posixpascal Oct 05 '15 at 06:36
  • Have you tried using another library to generate the pdf? If so, does it still shrink? This way, you can determine, with some degree of correctness, the source of the problem. – Pedro Lobito Oct 05 '15 at 10:07
  • I'll try it thanks. Gonna give some updates later this day. – posixpascal Oct 05 '15 at 10:44
  • I'm also going to do some tests with the prawn. I'll let you know the results after. – Pedro Lobito Oct 05 '15 at 10:53
  • You said "**The Image nested inside the PDF has a size of 213mm x 70mm with 300 DPI. In Pixel: 2515x827**"" but the image at https://github.com/posixpascal/chrome-printing-bug/blob/master/example.png is 2515x48. Which one are you really using ? – Pedro Lobito Oct 05 '15 at 11:38
  • I'm using 2515x827 but it doesn't make a difference when using 2515x48 because width is still changed in the printed picture. I cropped the image because I didn't want to embed a 827px wide image to stackoverflow. I'll change it when I can push again. – posixpascal Oct 05 '15 at 11:42
  • I couldn't understand why you use `at => [3.mm, 3.mm]` any particular reason for this ? This creates a left margin. At least in my tests. Can you try to generate the pdf with this code and do a test? http://pastebin.com/ctx4iKs5 . Here's the pdf generated by that code https://www.dropbox.com/s/seicffh77gt8zfo/print_scaling.pdf?dl=1 – Pedro Lobito Oct 05 '15 at 11:47
  • We're building an app which lets you create labels for bottles. I use the 3.mm margin for displaying cutting-lines (I removed the cutting lines in the output, but they don't make a difference). I have to use `:width => 213.mm` in the image tag otherwise it'll be bigger (your PDF for example takes up the whole width of the DIN A4 Landscape Page). The left-margin is fine, because the image only fills about 1/2 of the page (by explicitly setting :width to 213.mm) – posixpascal Oct 05 '15 at 12:16
  • Understood, I'll give it a try again asa I arrive to the office. – Pedro Lobito Oct 05 '15 at 13:05
  • Why don't you print directly from the pdf file instead of using chrome ? – Pedro Lobito Oct 09 '15 at 16:49
  • The PDf's are generated from a webpage and a customer is most likely gonna print it out. My last resort is to tell them to use Adobe Reader or System_Settings instead of Chrome :/. But this has to solved in some way right? – posixpascal Oct 10 '15 at 02:35

3 Answers3

1

This is my test results from what i have seen by using a windows system and a Mac ( Yosemite )

Windows :

Printed the PDF in Chome : Perfect - 213 mm

Printed in IE : Perfect - 213 mm. This was less before ( around 205-210ish ). So changed the default print settings :

Selected the Print option -> Used Print Dialog -> Selected the printer -> Print Preferences -> Advanced -> Paper Size -> Changed scaling manually -> tested A4, A5 and so on.-> A5 ( for some reason gave me 213 )

So i moved onto the Mac.

Mac Findings:

Changed Paper Size and tested the same : Size was 213 mm.

This was done like this : Apple Print

So naturally, i tested printing it through Chrome directly instead of opening the PDF through OSX -> Printed at 205 mm.

Tested with printscaling on prawn at :appdefault -> Printed at 213 mm.

Tested the same on Firefox -> lower than 205 - 210 mm.

So i dont really know if its a Chrome issue because its acting weird on Firefox for me.

So ultimately, these are my findings after testing out the code on my end.

  • Thank you, yes it has to do something with Firefox/chrome on macosx :/. I don't have a clue how to make this work. – posixpascal Oct 08 '15 at 08:46
  • When you print a webpage in chrome/firefox they offer you to use "100% / original size / full size" option which is pixel-perfect. Unfortunately they don't show this option when printing a PDF which is weird. I also tried using PDF.js to render the PDF which didn't help me either. Maybe I can't get it to work in these browsers... – posixpascal Oct 08 '15 at 08:54
  • @praszyk I am not sure if this has anything to do with MacOS Quartz Filters (see at /System/Library/Filters) . These filters are used for handling image conversions during printing or PDF conversion. – Santanu Dey Oct 11 '15 at 08:04
  • I'll check these filters later – posixpascal Oct 11 '15 at 11:03
  • @Joost my workaround was to add a text to the PDF to explain users how to print it. Unfortunately I didn't find a solution. It would made my day if someone solves this. – posixpascal Dec 28 '15 at 10:30
1

I experienced a similar 8 mm shrinkage using Chrome on Windows. Checked all my printer properties and settings and couldn't find what could be doing it. Turns out, I had the option "fit to page" ticked in the Chrome printing (ctrl+p) screen. Un-ticked it and reprinted a page, compared their widths and they were 8 mm off. Sometimes it's the simple things...

Elius
  • 11
  • 1
  • That does not work for PDFs if you print them in firefox/chrome. It does work when I use the system dialog to print. – posixpascal Apr 22 '16 at 18:56
0

In my experience, Chrome prints html usually smaller. It may have to do with WebKit engine having "smart shrinking" feature. I have come across to it here (text search shrinkage). Or, it might be just that, Chrome developers gave it a little tweak since people in the past complained that the stuff does not fit the print.

mehmet
  • 7,720
  • 5
  • 42
  • 48