shajin
shajin

Reputation: 3264

Prawn PDF generator: Make image with link

I use prawn to generate pdf and I want to include an image with link.I didn't
find a way to do it in its official documentation.Helps appreciated

Upvotes: 3

Views: 1540

Answers (1)

Gregory Brown
Gregory Brown

Reputation: 1378

To answer your question, we don't have high level support for image linking, but we do have support close to the PDF level.

So, you'd have to do something pretty terrible like this in the current Prawn release (0.14.0):

require "prawn"
require "open-uri"

Prawn::Document.generate("x.pdf") do
  image(open("http://prawn.majesticseacreature.com/images/example_pdf.png"), 
        :width => 300, :height => 300)
  link_annotation([bounds.absolute_left, 
                  bounds.absolute_top - 300, 
                  bounds.absolute_left + 300, bounds.absolute_top], 
                      :Border => [0,0,0], 
                      :A => { :Type => :Action, :S => :URI, 
                        :URI =>
                            PDF::Core::LiteralString.new("http://prawn.majesticseacreature.com") } )

end

Obviously, we'd be interested in a patch that would implement this feature at a higher level. Prawn has a lot of half-done stuff in it because the project went mostly inactive for a couple years, but we're now actively working on it again and welcome contributions!

Our repository is located here: https://github.com/prawnpdf/prawn

Upvotes: 5

Related Questions