【问题标题】:Disable link in pdfkit rails禁用 pdfkit rails 中的链接
【发布时间】:2016-12-01 16:09:28
【问题描述】:

我正在使用pdfkit gem 来生成 pdf 文件。我正在使用样式表来更改样式

  pdf = PDFKit.new(html, orientation: 'Landscape')
  pdf.stylesheets << File.join(Rails.root, 'app', 'assets', 'stylesheets', 'pdf.css')

在我的app/assets/stylesheets/pdf.css 中,我有:

  a {
    cursor: default;
    color: black;
  }

在我的 html 中,我有一个简单的 link_to 标签。我想禁用pdf中的链接,但是,上面的代码使链接的文本black但光标仍然是pointer。另外,我试过pointer-events: none。这似乎也不起作用。谁能帮我解决这个问题?

注意:我在this github issue 发现了类似的问题,但在这里找不到答案。

【问题讨论】:

    标签: css ruby-on-rails-4 hyperlink pdfkit disable-link


    【解决方案1】:

    我遇到了同样的问题,但我无法找到完美的解决方案。这是我做的一个简单的方法,它奏效了......

    <span class="show_in_html">
      <%= link_to(home_url) do %>
        <%=t('header.home')%>
      <% end %>
    </span>
    
    <span class="show_in_pdf">
       <%=t('header.home')%>
    </span> 
    

    在 home.css 中

    .show_in_html{显示:块}

    .show_in_pdf{显示:无;}

    在 pdf.css 中

    .show_in_pdf{display:block !important;}

    .show_in_html{显示:无!重要;}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-23
      • 1970-01-01
      • 2013-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多