ruby - Hexapdf:试图绘制白框,但它没有出现
问题描述
当我运行我的代码时,我的白框没有出现。我需要一个白框来覆盖现有的图像、文本,这样我就可以添加新的文本。如果我将颜色更改为 background_color: [255,255,180],则该框是透明的黄色。但是,我需要一个不透明的白色。
require 'hexapdf'
require 'pry'
doc = HexaPDF::Document.open('template.pdf')
pages = doc.pages
box = HexaPDF::Layout::Box.create(
width: 500, height: 500, content_box: true,
background_color: [255,255,255]
)
pages.each do |p|
canvas = p.canvas(type: :underlay)
box.draw(canvas, 20, 100)
end
doc.write("template_with_white_box.pdf")
解决方案
您需要使用canvas = p.canvas(type: :overlay)
它来工作,因为底层画布在现有页面下方绘制,而覆盖画布在现有页面上方绘制。
推荐阅读
- python - 在 django 中手动提供权限
- assembly - 对二进制到十六进制 ARM 编码感到困惑
- reactjs - 使用地图的反应js中的单选按钮
- c# - 将 DependencyProperty 实现到 TemplateBinding 时发生 XDG0008 错误
- ruby-on-rails - mongoid enum ArgumentError:参数数量错误(给定 1,预期 2..3)
- javascript - 我收到错误为 Uncaught TypeError: Cannot read property 'use' of undefined
- fortran - 使用 OMP 加速计算对称矩阵
- node.js - 创建要在 mongodb 中发送的数据时出现错误
- python - 如何从 HTML 源中找到结合了字母、符号和数字的标签?
- django - 在 Django Admin Detail 视图中显示 ManyToManyField