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:
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
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.
The printed PDF will show an image with 213cm width.
The printed PDF will show an image with 205mm width.
prawn page_size
to something lower than A4 (since the Image isn't bigger as A4 as well...).print_scaling
(there are 3 modes, :none
, :AppDefault
, :something_except_the_other_ones
(Read more about it here)
Chrome Printer Dialog
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.
Here is an example 300 DPI image which width is 2515 px: 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...
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.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With