You are here

Adding a printer-friendly link to your Drupal view pages

I love Drupal's Printer, email and PDF versions module, which allows you to add links to any of your content types to provide that content in a print-friendly fashion or in a PDF or simply to send to a friend via email.
Printer friendly links example
You can configure

  1. Which of those links to include (above I include only printer-friendly and email links)
  2. Whether to display the links as icons only, text only, or both (I have both above)
  3. Which content types should automatically include those links
  4. Where to display them (above the post, below the post, etc)

Additionally, you can even use the 'Manage Display' screen on your content type to specify which fields you want in your print display (this display is not added by default, but you can add it):
Printer friendly configuration for nodes

So far, so good.  The only problem is when you want to include these icons on a view or otherwise-generated page!  The UI allows for you to place these links on specific content types when you're editing that content-type looks like this (on the content type's edit screen):
printer_friendly2

No such options exist when you're creating a page via a View. When I got a request to place a 'Printer-friendly' link on a view recently, I started thinking about how to do that.  If I didn't have a printer-friendly way of displaying the screen, the print screen included a lot of extra information (blocks, etc), which were not necessary in the printed versions of the page. So I explored what the URL behind the 'Printer-friendly' link actually was, and it turns out, it's nothing more than:

http://<YOUR-WEB-URL>/print/<NID>

So, to mimic that, I added a Header (Global: text) box to my view and placed in the following (text format = 'PHP code' for this):

<?php $current_url = getenv('REQUEST_URI'); ?>
<img src='/sites/all/modules/contrib/print/icons/print_icon.gif'>
​<a href='/print<?php print $current_url; ?> '>Printer-friendly version</a>

As you can see, what the above does is get the current URL (my view includes filters, so the URL is dynamic: folks may be looking at different lists, based on their chosen filters), then grabs the icon from the actual print module (modify this to fit the location of the module in your own installation), and builds the link. It works wonderfully!  Prepares a printer-friendly version sans footers, headers, blocks, and respects the chosen filters of the view, since they are part of the URL that is generated. Let us know if you try this!

Share

Comments

Thanks for taking the time to share this. Works great, even for a bum website builder like me.

<a href="/print/#" alt="Печать" target="_blank"><img src="/sites/all/modules/print/icons/print_icon.png" title="Печать" alt="Печать"></a>
no php

Absolutely!  Good call on that...

Thank you - this is exactly what I was looking for.

Great

Go to the settings page, click the 'links' tab then under 'show link in system (non-content) pages' select the radio button 'show on every page except the listed pages' and now it shows on all views pages too.

That's awesome!  Thanks!  This functionality definitely did not exist when I was looking for it some years ago.  This pretty much makes this tutorial obsolete, but thank goodness it exists now.  :-)

Great tip, thanks for that. I think this even can be used in a much more flexible manner in just creating a block, adding the small code and use the block anywhere you like (also on views pages).

You're fucking awesome!!!

Thanks for the helpful post! Is it possible to get this to work with an accordion view? I have enabled 'show link in system (non-content) pages' but only the first two rows of the accordion view display in the print file. Ideally, I would like all row headers and content to display on the print file. Thanks again.

i have multilingual sites and after use above code go to page not found page.
after delete en or ar before current url fix this broblem.
how to fix this problem???

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.