Question

I have a pdf that is generated using the wicked_pdf gem. My problem is that i see the "download pdf" link in the pdf also. How to remove that link from the rendered pdf? I read about css media types but dont know how to implement that. can anyone help? or is there any other way other than using css media types?

Was it helpful?

Solution

I'm assuming that you are using the pdf format to determine if the user wants a pdf version. You can check if the request format is pdf in your view

<% unless request.format.to_sym == :pdf %>
  <%= link_to 'Download PDF', { format: :pdf } %>
<% end %>

OTHER TIPS

Add the wicked_pdf helper to load a css file

<%= wicked_pdf_stylesheet_link_tag "print" -%>
<div class="export">
 <%= link_to "Download pdf", "http://example.com/download.pdf" %>
</div>

and in your css file you can add code to hide those links under the css selector 'export' using

@media print {
 .export {
  display: hidden;
 }
}

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top