Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prawn - Links inside table cells

I am trying to generate PDFs with Prawn. Inside my PDF template I have tables with cells. In one of those cells I have an email address:

cell_email = pdf.make_cell(:content => booking.user_email, :border_width => 0)

I want to make email to link to "mailto" link. I know I can link some way like this:

pdf.formatted_text([{:text => booking.user_email, :link => "mailto: #{booking.user_email}"}])

However combining those two lines (giving formatted text as a content) doesn't work:

cell_email = pdf.make_cell(:content => pdf.formatted_text([{:text => booking.user_email, :link => "mailto: #{booking.user_email}"}]), :border_width => 0)

Any ideas how can I overcome this issue (create an email link inside the table cell)?

Kind Regards and Many Thanks!

like image 893
alexs333 Avatar asked Jul 09 '12 07:07

alexs333


2 Answers

You can specify inline_format for the cell and create the link yourself:

cell_email = pdf.make_cell(
  :content => "<link href='mailto:#{booking.user_email}'>#{booking.user_email}</link>",
  :inline_format => true
)

You can specify inline_format for the whole table, too:

table data, :cell_style => { :inline_format => true }

Prawn's inline_format supports <b>, <i>, <u>, <strikethrough>, <sub>, <sup>, <font>, <color> and <link>.

like image 117
Stefan Avatar answered Nov 11 '22 10:11

Stefan


The following underlines the link and gives it a blue colour:

link = make_cell(content: "<color rgb='0000FF'> <u> <link href='https://stackoverflow.com/questions/11390505/prawn-links-inside-table-cells'> #{booking.user_email} </link></u> </color>", inline_format: true)

data = [[link]]

table(data,:header => true, :row_colors =>["F0F0F0","FFFFCC"]) do      
end
like image 32
BenKoshy Avatar answered Nov 11 '22 10:11

BenKoshy