2016-02-25 16 views
3

我使用rghost-barcode生成阿茲臺克人條形碼。但每次創建條形碼時,都會將其保存在A4頁面上,條形碼位於左上角。如何僅使用rghost將條形碼存儲爲.png而不是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" 

這是結果:

my_barcode result

+0

您可以在初始化時更改文檔大小嗎? – tadman

回答

1

寶石使用PostScript/ghostsript作爲後端,因此它總是產生的文件,然後在此文檔中插入條形碼。這些文件似乎默認爲A4。

根據rghost wiki,您可以指定文件應該多大:

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

恐怕尺寸爲英寸(維基沒有規定的尺寸)

0

你必須設置紙張尺寸定位您的條形碼。請注意,條碼的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)應該工作。

相關問題