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:
- https://code.google.com/p/chromium/issues/detail?id=97972
- https://code.google.com/p/chromium/issues/detail?id=67091
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:
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...