【发布时间】:2026-01-11 12:50:02
【问题描述】:
当我运行我的代码时,我的白框没有出现。我需要一个白框来覆盖现有的图像、文本,这样我就可以添加新的文本。如果我将颜色更改为 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")
【问题讨论】: