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

10,710

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

Solution 2

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

Share:
10,710
posixpascal
Author by

posixpascal

#☝️ Hi. I like emojis, open source projects, breaking things, writing tests, blaming the compiler and other stuff you usually read in this section from a developer. Turning ☕️ caffeine into code for about 14 years now. JavaScript and Ruby enthusiast. But more JavaScript than Ruby. Fluent in PHP, Python and Shell scripts and whatever you see on my GitHub. ❤️ Things I love I love Web, APIs, Backends, aws, good stuff. Terraform, Nuxt, React. Hop on the event bus and drive down microservice lane. Big fan of Sandi Metz's work and talks. I love cats, but don't have one. I would call her Knuckles tho. So I built some more or less cat related projects like... 📍A Multiplayer Geographical Guessing Game @ geofind.io 🗺 A Smart Wiki-Based Audio Tour Guide 🐈 A peer 2 peer filesharing service called peer.cat. 🍕 Built a B2B POS Platform mainorder.de 🕵️ Found Lovoo privacy vulnerability 🤞 Being transparent at my personal site. Play Chess with me! 🔨 Made my personal dotfiles repo Built lots of sites, platforms, apps as well, checkout my github. Deal is simple: Give me code and I fix your stuff, or I fix my own stuff, or build something nice on top of your project, or build something broken on top of it. Depends on the amount of coffee you feed me basically. 📖 Quotes people love 🚧 Move fast, break things. and 😐 Why would jenkins do this 🗣 Chit-chat Just drop me a message anywhere you like. Otherwise, feel free to do whatever you want.

Updated on July 20, 2022

Comments

  • posixpascal
    posixpascal almost 2 years

    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
    posixpascal over 8 years
    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
    posixpascal over 8 years
    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...
  • Santanu Dey
    Santanu Dey over 8 years
    @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.
  • posixpascal
    posixpascal over 8 years
    I'll check these filters later
  • posixpascal
    posixpascal over 8 years
    @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
    posixpascal about 8 years
    That does not work for PDFs if you print them in firefox/chrome. It does work when I use the system dialog to print.