Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.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 如何使用rghost将条形码仅存储为.png而不是A4页面?_Ruby_Barcode - Fatal编程技术网

Ruby 如何使用rghost将条形码仅存储为.png而不是A4页面?

Ruby 如何使用rghost将条形码仅存储为.png而不是A4页面?,ruby,barcode,Ruby,Barcode,我正在使用生成Aztec条形码。但每次我创建一个条形码,它就会保存在一个完整的A4页面上,条形码在左上角 为什么会这样?如何仅将条形码保存到PNG,尺寸为我想要的尺寸(720px 720px) 以下是我目前正在尝试的: doc = RGhost::Document.new doc.barcode_azteccode('This is Aztec Code',{:text=>{:size=>8}, :format=>"full"}) doc.render :png, :reso

我正在使用生成Aztec条形码。但每次我创建一个条形码,它就会保存在一个完整的A4页面上,条形码在左上角

为什么会这样?如何仅将条形码保存到PNG,尺寸为我想要的尺寸(720px 720px)

以下是我目前正在尝试的:

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"
这就是结果:


gem使用postscript/ghostsript作为后端,因此它总是生成文档,然后将条形码插入到该文档中。这些文档似乎默认使用A4

根据,您可以指定文档的大小:

doc = RGhost::Document.new :paper => [15,10]

恐怕尺寸单位是英寸(wiki没有说明尺寸)

您必须设置纸张尺寸和条形码的位置。请注意,条形码的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)都可以工作。

初始化文档时,是否可以更改文档大小?