Prawn : adding background image of larger resolution

Viewed 6865

I'm creating a pdf book where I need to put a background image for each page.

The size of the page is (576 x 576) and the size of the background image is 2700 x 2700 (300 dpi.) (These sizes are the requirements so cannot be adjusted). My problem is - the background image appears out of proportion in the page. How can I fix this ? Here's my code:

 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, 
:background => "#{Rails.root.to_s}/public/images/pdf/bg_blank_low.jpg" ) do |pdf|
    ....
    ....
    ....
)

Is there any other way by which I can place the image of 300 dpi as a background image.

I even tried adding pdf template as a background, but still no luck.

Any suggestion or hint will be much appreciated.

Thanks.

2 Answers

If you only have one PDF page, a solution is to just don't use the background property at all, but just place the image at the first position of each page and define width as the full width with

pdf.bounds.width
Related