How to create a printer friendly HTML page?

How do I change or remove layouts from my application in a specific Rails view so that my users have a more pleasant printing experience? (No navigation bar or other additional data)

I have been banging my head on the table for several hours, trying to figure it out. I tried using render layout: false without success.

I tried to create such an action as shown below, but for me this did not work:

 def print respond_to do |format| format.html { render layout: false } end end 

I tried to link this action using the following:

<%= link_to 'Printer Friendly Version', product_path(@product), :action => 'print', target: '_new' %>

Am I just here? How can I better approach this obstacle? I don't want to use PDF or Javascript, I just want to display HTML compatible with the printer.

+7
html css ruby-on-rails printing
source share
1 answer

You can only do this with CSS as follows: see the full article here.

 <style type="text/css"> @media print{ body{ background-color:#FFFFFF; background-image:none; color:#000000 } #ad{ display:none;} #leftbar{ display:none;} #contentarea{ width:100%;} } </style> 

It uses simplified CSS when it detects that the page is being sent to the printer.

- link W3Schools - .

Also see this article :

Summary: How to make printer friendly web pages

If your website delivers value to your audience, it is most likely going to print pages. Keeping desktop printers running your website is another aspect of building a great user experience.

In this article, we will quickly look at the use of cascading style sheets for the design of printed web pages.

+12
source share

All Articles