Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome: How to print PDF with original size (100%, no scaling/shrinking)

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: 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...

like image 817
Pascal Raszyk Avatar asked Sep 29 '15 16:09

Pascal Raszyk


2 Answers

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.

like image 162
Vyshnav B C Avatar answered Oct 16 '22 16:10

Vyshnav B C


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...

like image 37
Elius Avatar answered Oct 16 '22 17:10

Elius