【问题标题】:Prawn - Links inside table cells大虾 - 表格单元格内的链接
【发布时间】:2012-07-09 07:13:33
【问题描述】:

我正在尝试使用 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)

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

诚挚的问候,非常感谢!

【问题讨论】:

    标签: ruby-on-rails ruby prawn


    【解决方案1】:

    您可以为单元格指定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支持&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;strikethrough&gt;&lt;sub&gt;&lt;sup&gt;&lt;font&gt;&lt;color&gt;和@98765433@4。

    【讨论】:

    • 太好了,谢谢!我唯一需要注意的是,如果您有嵌套表,则需要在初始化程序块中添加内联格式,如下所示:table(data) do; cells.each { |c| c.inline_format = true if c.respond_to?(:inline_format) }; end
    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2014-11-14
      • 1970-01-01
      • 1970-01-01
      • 2012-09-03
      • 2012-03-01
      • 2012-05-11
      • 2021-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多