禁用 pdfkit Rails 中的链接

问题描述 投票:0回答:1

我正在使用 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
。这似乎也不起作用。谁能帮我解决这个问题吗?

注意:我在这个github问题中发现了类似的问题,但无法在这里找到答案。

css ruby-on-rails-4 hyperlink pdfkit disable-link
1个回答
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{display:block}

.show_in_pdf{display:none;}

在pdf.css中

.show_in_pdf{display:block !important;}

.show_in_html{display: none !important;}
© www.soinside.com 2019 - 2024. All rights reserved.