今天我在 Chrome 的打印行为中遇到了一个奇怪的错误。
当我尝试使用 Chrome 打印动态创建的 PDF 时(也在火狐浏览器中),PDF 中的每个图像都会变小一点(8 毫米)。
在 Adobe Reader/Acrobat/MacOSX 默认打印机对话框中也不会发生这种情况。
让我详细解释一下到目前为止我的代码:
动态PDF:
I use prawn
使用以下代码动态创建 PDF A4(横向格式):
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
PDF 中的嵌套图像:
嵌套在 PDF 中的图像的大小为213mm x 70mm
with
300 DPI
。像素:2515x827。
我使用 RMagick 创建图像,但大小、dpi 和到目前为止一切似乎都不错。所以暂时没有进一步的解释。
预期结果:
打印的 PDF 将显示宽度为 213 厘米的图像。
实际结果:
打印的 PDF 将显示宽度为 205 毫米的图像。
到目前为止我尝试过的
- 设置
prawn page_size
低于 A4 的大小(因为图像也没有 A4 大......)。
- 玩弄
print_scaling
(有3种模式,:none
, :AppDefault
, :something_except_the_other_ones
(在这里阅读更多相关信息) https://github.com/prawnpdf/prawn/blob/master/manual/document_and_page_options/print_scaling.rb
- 给图像固定高度(70mm)
- 尝试使用由
Chrome Printer Dialog
- 在 Windows Chrome 下测试(那里是 213mm,奇怪),也许它与 MacOSX Chrome 有关?
- 不幸的是在 IE11 (205mm) 下测试。
这些都没有做任何事情。
我查看了 Chromium 的 Bugreporters,发现有 2 个人可能和我有同样的问题:
- https://code.google.com/p/chromium/issues/detail?id=97972 https://code.google.com/p/chromium/issues/detail?id=97972
- https://code.google.com/p/chromium/issues/detail?id=67091 https://code.google.com/p/chromium/issues/detail?id=67091
最后一个是 2013 年触及的,但没有人说任何对我的案例真正有用的东西。
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 https://github.com/posixpascal/chrome-printing-bug/blob/master/example.png)
这是一个 PDF 示例
直接链接: 直接链接 https://github.com/posixpascal/chrome-printing-bug/raw/master/output.pdf
GitHub PDF 查看器: https://github.com/posixpascal/chrome-printing-bug/blob/master/output.pdf https://github.com/posixpascal/chrome-printing-bug/blob/master/output.pdf
Github 存储库,包含示例图像和 pdf 生成器脚本
https://github.com/posixpascal/chrome-printing-bug https://github.com/posixpascal/chrome-printing-bug
不幸的是我无法改变图像的宽度(甚至不能改变像素)。
有人遇到过同样的问题吗?
有任何想法吗?我想这是一个有趣的谜题......:x
当我使用 Chrome 打印普通图像或网站时,会出现“使用原始尺寸”或“100% 尺寸”选项,而打印 PDF 时则没有这些选项。
我还尝试制作网页而不是 PDF 并将图像宽度设置为213mm
这也不起作用......