2011-08-11 11 views
0

イメージをすべてのページの背景として配置したいと思います。これは私のコードです:PDF Prawn:テキストオーバーライドの問題

Prawn::Document.generate("#{Rails.root.to_s}/public/#{filename}.pdf", :page_size => [576,576], :left_margin => 50,:right_margin => 50, :page_layout => :portrait, :skip_page_creation => true, :skip_encoding => true) do |pdf| 

    pdf.repeat :all do 
    pdf.image open(APP_CONFIG['site_url']+"/images/pdf/bg_blank_high.jpg"), :at => [-pdf.bounds.absolute_left, pdf.bounds.absolute_top], :width => 576, :height => 576 
    end 

    pdf.start_new_page(:margin => [75,50,50,50]) 
    pdf.fill_color "8c8464" 
    pdf.text story.contents, :size => 12, :align => :left, :leading => 3 
end 

問題は - すべてのページのテキストを上書きします。

画像の上にテキストを配置したり、画像を「送り返し」や他のアイデアにする方法はありますか?彼らはテキストでカバー画像の一例として、これを与えるエビマニュアルで

答えて

1

# images/absolute_position.rb 
# One of the options that the image method accepts is :at. If you've read some of the graphics 
# examples you are probably already familiar with it. Just provide it the upper-left corner where you 
# want the image placed. 
# While sometimes useful this option won't be practical. Notice that the cursor won't be moved after the 
# image is rendered and there is nothing forbidding the text to overlap with the image. 

y_position = cursor 
text "The image won't go below this line of text." 
image "#{Prawn::BASEDIR}/data/images/fractal.jpg", :at => [200, y_position] 
text "And this line of text will go just below the previous one." 

だから私は、これはあなたが文書または多分あなたのカーソルを構築する方法に問題があるかもしれません伝えることができるものから配置。

1

テキストがレンダリングされた後、repeat-blockのコードが呼び出されたと思われるので、'の上に'のテキストを置きます。 提供されているコードスニペットは、単一の画像に関係するため、機能します。

prawn_document(filename:  "filename.pdf", 
       background:  path_background_image) do |pdf| 
... 

あなたのために働くことがあります。しかしそれはlow_res(72 dpi)の画像しか提供しません。

解像度が背景画像に設定するすることを可能にするためのプル要求があります: https://github.com/sandal/prawn/pull/292

関連する問題