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!
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>
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With