Community Documentation

Add 'Print-friendly' support for a calendar

Last updated December 29, 2010. Created by LeeHunter on August 29, 2006.
Edited by elgandoz, add1sun, alanburke. Log in to edit this page.

Required
Print Module > http://drupal.org/project/print
Event Module > http://drupal.org/project/event

The excellent Print Friendly Pages module
http://drupal.org/project/print
does an excellent job on producing nicely formatted output suitable for printing.

However, as the 'Month-view' calendar produced by the events module
http://drupal.org/project/event
isn't actually a node, no 'printer friendly version' link appears.

Here's how to achieve this:

First thing, create a page using this code

<?php

print event_page($year = NULL, $month = NULL, $day = NULL, $view = NULL, $types = NULL, $tids = NULL, $duration = NULL)

?>

Make sure to use PHP as the input type.

This should output the calendar within a node, with the requisite 'printer friendly version' link appearing at the bottom.

Advanced Usage

Create a new menu item, that links directly to the 'print-friendly version'. EG http://example.com/node/123/print.
Create a new menu, and place this menu item as the sole item within in.
Go to 'administer > blocks'.
Enable the block for the new menu.
Configure the 'block visibilty', and set it only to appear on the Event page.

Slightly More Advanced Usage
Place the block in the 'content' region [This does not exist in all themes!]
The new block will appear below the calendar, more or less the same as a standard 'printer friendly version' link!

For Bonus Points:

Ammend the Print module to include event.css file.
By default, the print module will not include the CSS files that make the event calendar 'pretty'.

Open the print.node.tpl.php file within the print module folder.

Add this line

  <style type="text/css">
    @import url(<?php print  $base_path . drupal_get_path('module', 'event') .'/event.css';?>);
    </style>

below the

<style type="text/css">
      @import url(<?php print $node->printcss; ?>);
    </style>

This will add the event.css file to the print-friendly version pages.

Comments

can you do it w/ a custom views page?

great adaptation! i would like to be able to do the same with a custom calendar view. replacing the event_page with the name of the view, or various permutations like that does not seem to be doing the trick. where/what should i try?

thanks! isaac

Different, more flexible (?) solution

With the above solution, you can only print the current calendar (or whatever code is permanently written into that node page).

I've found an alternative solution, based on the fact that *any* page URL - if preceded by "print/" - will render in the print format. In looking for good solutions to pull the URL then modify it, I actually went back to the Print module, and pulled several lines. This turned out to be the best solution, because this code also pays attention to how you have set up your print module.

I took these lines below and put them into a block that appears below the content. In block visibility I have selected "event" and "event/*".

I now have a link for every calendar page / style (table, list, day) that renders in print format.

if ($path === NULL) {
      $path = PRINT_PATH .'/'. preg_replace('!^node/!', '', $_GET['q']);
      $query = print_query_string_encode($_GET, array('q'));
      if (empty($query)) {
        $query = NULL;
      }
    }
    $format = theme('print_format_link');
    return '<span class="print">'. l($format['text'], $path, $format['attributes'], $query, NULL, TRUE, $format['html']) .'</span>';

undefined function

Call to undefined function print_query_string_encode() in /includes/common.inc(1355) : eval()'d code on line 4
drupal 5.12

changed to drupal_query_string_encode()
also changed PRINT_PATH to 'print'

(print module must be installed)

this is a nice solution. it might be good to add some css that hides the select boxes for filtering, and this block should ship with the event module.

new way

according with the module documentations (http://drupal.org/node/190173#linklocation), this is the right way:

<?php
print print_insert_link();
?>

but putting this the code for me doesn't work! Any suggestion about that?
now i'm using the method posted above and it's ok, but it converts the html in special chars..it spoils my icon! good solution anyway!
<?php
   
if ($path === NULL) {
     
$path = 'print/'. preg_replace('!^node/!', '', $_GET['q']);
     
$query = drupal_query_string_encode($_GET, array('q'));
      if (empty(
$query)) {
       
$query = NULL;
      }
    }
   
$format = theme('print_format_link');
    return
'<span class="print">'. l($format['text'], $path, $format['attributes'], $query, NULL, TRUE, $format['html']) .'</span>';
?>

Calendar Printing - filtered page

I am using the code below to place a print link in a custom content block (have printer friendly module installed) below my calendar page.

if ($path === NULL) {
      $path = PRINT_PATH .'/'. preg_replace('!^node/!', '', $_GET['q']);
      $query = print_query_string_encode($_GET, array('q'));
      if (empty($query)) {
        $query = NULL;
      }
    }
    $format = theme('print_format_link');
    return '<span class="print">'. l($format['text'], $path, $format['attributes'], $query, NULL, TRUE, $format['html']) .'</span>';

This code works great for printing monthly, weekly or daily calendar pages. However, when I filter a calendar page using taxonomy terms, the link url does not change and the print page does not change to reflect the filtered data.

My default monthly calendar page url is "example.com/calendar/events".

An example url of a filtered page becomes "example.com/calendar/events?term_node_tid_depth[]=8" ....however when selecting the print link it still points to url "example.com/calendar/events"

How can I get the print link to recognize/point to the full filtered url?

Thanks,
Jeff

A good place to modify the

A good place to modify the print node structure is in hook_nodeapi().

We can use $node->build_mode = 'print' to determine if we are going to print the content.

Note that $node->build_mode == 'print' is, in print-6.x-1.11.tar.gz, NOT true when the node is loaded.
We have to wait for the view operation instead.

<?php
function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch (
$op) {
  
   
// load node
   
case 'load':
     
// $node->build_mode != NODE_BUILD_PRINT
     
break;

   
// view node
    // this is called after load when when the node content structure is
    // prepared in node_build_content.
   
case 'view':

      if (
$node->build_mode == NODE_BUILD_PRINT) {
         
// modify structure for printing
     
}
      break;
    
  }
}
?>
_______________________
calendar printing

Page status

Needs technical review

Log in to edit this page

About this page

Drupal version
Drupal 6.x

Site Building Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here