Reputation: 125
I am using prawn gem for generating pdf in ROR. Everything was going very smoothly before working with images. When I am trying to insert an image into the pdf the image is drawn well. But, if the image is located in end of the page in pdf or if the image exceeds the page height then the image gets broke down and the pdf data after the image also gets broken. Please find the image that I have attached for this issue
In the image after the Buildout text, the image is getting broke down and the pdf data after that image also broke down.
I am using gem 'prawn', '2.0.1' gem 'prawn-table', '~> 0.1.0' for the pdf generation and ruby ruby 2.1.2p95
any one can help me on this. Thanks for advance for the solution.
Upvotes: 0
Views: 461
Reputation: 1089
You can always control :height, :width and :at (location) of the image in Prawn:
Prawn::Document.generate("images.pdf", :page_layout => :landscape) do
photo1 = "#{Prawn::BASEDIR}/data/images/photo1.jpg"
image photo1, :at => [50,450], :width => 450, :height => 450
end
So you can manage if is located in end of the page or if the image exceeds the page height.
You can define size (height) like this:
# New document, A4 paper, landscaped (height = 841.89)
pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
# New document, Custom size (height = 300)
pdf = Prawn::Document.new(:page_size => [200, 300])
Upvotes: 0
Reputation: 23711
I haven't used the prawn gem. But you can try your luck with Wicked PDF. This is also one of the gem most developers use to generate pdf. You can have customized CSS for the pdf layout. Hope this might solve your problem.
Upvotes: 1