Chrome:如何打印原始大小的PDF(100%,不缩放) [英] Chrome: How to print PDF with original size (100%, no scaling/shrinking)
问题描述
当我尝试使用Chrome打印动态创建的PDF(在Firefox中也是 )时,PDF中的每个图像都会变小一点(8mm)。
在Adobe Reader / Acrobat / MacOSX默认打印机对话框中都不会发生这种情况。
现在让我更详细地解释我的代码:
dynamic PDF:
我使用 prawn
来动态创建PDF使用此代码的A4(横向格式):
require'prawn'
requireprawn / measurement_extensions
类CustomPdf<对虾::文档
def初始化(标签)#A4
super({
:page_size =>A4,
:page_layout =>:风景,
:margin => 0,
:print_scaling =>:none})
imagemy_image.png,:width => 213.mm,:at => [3.mm,3.mm]
end
end
嵌套图像在PDF里面:
嵌套在PDF中的图像的大小为 213mm x 70mm
,
300 DPI
。在像素:2515x827。
我使用RMagick创建图像,但尺寸,dpi和所有目前为止似乎没有问题。所以目前没有进一步的解释。
预期结果:
打印的PDF将显示213cm宽度。
实际结果:
打印的PDF将显示205mm宽的图像。
我到目前为止所做的尝试
- 设置
prawn page_size
到低于A4的东西(因为图片不像A4那么大)。
- 玩弄
print_scaling
code>(有三种模式,
:none
,:AppDefault
,: something_except_the_other_ones
如果Imgur将分辨率更改为72,则可以从存储库拉示例图像(链接: https://github.com/posixpascal/chrome-printing-bug/blob/master/example.png ) / p>
以下是一个示例PDF
直接链接:直接链接
GitHub PDF查看器: https: //github.com/posixpascal/chrome-printing-bug/blob/master/output.pdf
https://github.com/posixpascal/chrome - 打印错误
不幸的是,我无法改变图像的宽度(甚至不是一个像素)。
有人经历过同样的问题吗?
有什么想法?这是一个有趣的谜题,我猜... ... x
当我用Chrome打印一个普通的图像或网站时,打印PDF时没有使用原稿尺寸或100%尺寸选项。
我也尝试制作网页而不是PDF,设置图像的宽度为 213mm
,这也不起作用...
这是我使用Windows系统和Mac(Yosemite)所看到的测试结果
Windows:
在Chome上打印PDF:完美 - 213毫米
印刷在IE:完美 - 213毫米。这之前(205-210左右)较少。所以改变了默认的打印设置: b
$ b
选择打印选项 - >使用打印对话框 - >选择打印机 - >打印首选项 - >高级 - >纸张大小 - >改变手动缩放 - >测试A4,A5等.-> A5(由于某种原因给了我213)
改变纸张大小并测试相同的:尺寸为213毫米。
这样做是这样的:打印在205毫米。
经过对虾的printscaling测试:appdefault - >以213 mm打印。
在Firefox上测试相同 - >低于205 - 210毫米。所以我真的不知道它是否是一个Chrome的问题,因为它在Firefox上的行为奇怪我。所以最终,这些都是我在测试完我的代码之后的发现。
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...
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.
这篇关于Chrome:如何打印原始大小的PDF(100%,不缩放)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!