Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 将图像插入到Prawn生成的PDF时出现奇怪的边框_Ruby On Rails_Ruby_Pdf_Prawn - Fatal编程技术网

Ruby on rails 将图像插入到Prawn生成的PDF时出现奇怪的边框

Ruby on rails 将图像插入到Prawn生成的PDF时出现奇怪的边框,ruby-on-rails,ruby,pdf,prawn,Ruby On Rails,Ruby,Pdf,Prawn,我在这个链接上有一个图像: 我正在尝试使用以下方法将此图像作为背景插入pdf: image_path = "..." #path to the image pdf = Prawn::Document.new pdf.image image_path, width: pdf.bounds.width, height: pdf.bounds.height pdf.render_file "test.png" 输出PDF位于以下链接: 问题是在PDF中,您可以在图像的顶部和底部看到灰色边框(如果看

我在这个链接上有一个图像:

我正在尝试使用以下方法将此图像作为背景插入pdf:

image_path = "..." #path to the image
pdf = Prawn::Document.new
pdf.image image_path, width: pdf.bounds.width, height: pdf.bounds.height

pdf.render_file "test.png"
输出PDF位于以下链接:

问题是在PDF中,您可以在图像的顶部和底部看到灰色边框(如果看不到边框,请尝试放大/缩小,您将看到边框)

这是怎么回事?我认为图像可能有问题,但我不确定。我希望你们能有个更好的想法


提前谢谢

与其设置高度和宽度,不如尝试设置位置,让图像缩放到最适合可用空间(匹配高度、匹配宽度、匹配两者)?您可能会看到图像的某些伪影被拉伸到pdf区域(如果图像尺寸与pdf不完全匹配)

pdf.image image_path,
          :position => :center,
          :vposition => :center,
          :fit => [pdf.bounds.width, pdf.bounds.height]