我正在使用rghost-barcode生成一个阿兹特克条形码。但每次我创建一个条形码,它都会保存在一个完整的A4页面上,条形码在左上角。
为什么会发生这种情况?如何将条形码仅保存到具有所需尺寸(720px X 720px)的PNG。
这是我目前正在尝试的:
doc = RGhost::Document.new
doc.barcode_azteccode('This is Aztec Code',{:text=>{:size=>8}, :format=>"full"})
doc.render :png, :resolution => 100, :filename => "my_barcode.png"这就是结果:

发布于 2016-02-26 09:05:18
gem使用postscript/ghostsript作为后台,所以它总是生成文档,然后在这个文档中插入条形码。并且这些文档似乎将A4作为默认设置。
根据rghost wiki,您可以指定文档应该有多大:
doc = RGhost::Document.new :paper => [15,10]恐怕尺寸是以英寸为单位的(维基没有说明尺寸)
发布于 2017-10-29 19:29:20
您必须设置纸张大小和条形码的位置。请注意,条形码的y位置位于页面底部。经过一些试验和错误之后,例如,这可以很好地工作:
#paper is x , y
doc=RGhost::Document.new :paper => [4.4, 3.2]
#y is from bottom of page
doc.barcode_ean13('2112345678900',
{:text=>{:size=>7},
:enable=>[:text],
:scale=>[1,1],
:x => 0.5, :y => 0.4})
doc.render :png, :resolution => 100, :filename => "ean13.png"如果您想要增加代码的分辨率,只需将比例增加一倍,以及所有其他参数(纸张大小和条形码x,y)应该可以工作。
https://stackoverflow.com/questions/35639443
复制相似问题