5

我正在尝试用 Prawn 生成 PDF。在我的 PDF 模板中,我有带有单元格的表格。在其中一个单元格中,我有一个电子邮件地址:

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

我想通过电子邮件链接到“mailto”链接。我知道我可以像这样链接:

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

然而,结合这两行(将格式化文本作为内容)不起作用:

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

有什么想法可以解决这个问题(在表格单元格中创建一个电子邮件链接)?

亲切的问候和非常感谢!

4

2 回答 2

9

您可以inline_format为单元格指定并自己创建链接:

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

您也可以inline_format为整个表指定:

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

大虾的inline_format支持<b>, <i>, <u>, <strikethrough>, <sub>, <sup>, <font>,<color><link>.

于 2012-07-09T08:46:48.623 回答
2

以下为链接加下划线并赋予其蓝色:

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
于 2020-05-22T06:42:09.400 回答