Community Documentation

Print: 5. Frequently Asked Questions

Last updated August 4, 2011. Created by jcnventura on November 7, 2007.
Edited by csdco, texas-bronius, drupal-id.com, JaredAM. Log in to edit this page.

Questions

  1. I have enabled the module, but the PF page link is not showing up!
  2. The Printer-friendly version in book nodes is not working correctly.
  3. The book pages still display the text "Printer friendly pages," and no icon
  4. Can I replace the 'Printer-friendly version' link with an icon?
  5. I can't see the icon-only option!
  6. But can I use my own icon?
  7. Is it possible to place the PF link somewhere else?
  8. Is it possible to change the styles used in the PF page?
  9. Is it possible to define a template for a specific content type?
  10. I don't like the template used. Can I use another?
  11. I am using a custom template but nothing seems to be working correctly. What's the problem?
  12. The blocks I have in the 'content' region are not showing up! Why?
  13. I see a lot of PHP warnings of the type: warning: array_map() [function.array-map]: Argument #2 should be an array in /home/site3/html/sites/all/modules/print/include/abstract_renderer.cls.php on line nnn
  14. dompdf or TCPDF don't work!
  15. Inline php script doesn't work in dompdf
  16. I am a module author/maintainer. Is there a way to know when a node is being built by the print module so that I can disable my output?
  17. How can I make the e-mail form show in a pop-up window?
  18. I have a problem/question not answered here. Where can I go for help?
  19. Domdpdf doesn't like shorthand css?
  20. How to add captcha?
  21. How to add a gmap to a pdf?
  22. The currently selected version of wkhtmltopdf () is not supported. Please update to a newer version.
  23. How do I send a PDF by e-mail?

Answers

I have enabled the module, but the PF page link is not showing up!
There may be several reasons for this, but try the following in order (you must have appropriate permissions to perform some of these steps - login as user #1 if you don't):
  1. Make sure that the module is enabled (the check-box next to 'Printer-friendly pages' in admin/build/modules must be ticked).
  2. In admin/user/access under the print module heading make sure that you have enabled access to the desired groups. In most cases, you will want to tick the 'access print' boxes for all groups, and clear the 'admin print' boxes for all groups except the administrator group (if defined).
  3. In admin/settings/print, make sure that you have enabled the PF link.
  4. For each content type x, check in admin/content/types/x that the 'Show printer-friendly version link' is enabled.
The Printer-friendly version in book nodes is not working correctly.
If you're using Drupal 4.7.x, that PF link is managed by the book module and this module has nothing to do with it. If you're using Drupal 5.x or later try to enable the 'Take control of the book module printer-friendly link' in the Printer-friendly settings form and see if you like it better that way.
The book pages still display the text "Printer friendly pages," and no icon
It's not a bug.. The 'take control' is precisely that.. Take control, not replace. The book module's link is still left intact, but instead of generating the page via the book module, some of it is generated by the print module.
It's not easy to solve the problem, as I don't want to hijack core features more than I need to, and in this case, there may be themes/modules that are already handling the PF page link in book nodes in ways that would be broken if I were to completely replace the link.
Can I replace the 'Printer-friendly version' link with an icon?
Yes. In the module's settings, set the page link to 'icon only'.
I can't see the icon-only option!
The advanced link options fieldset is a collapsible fieldset, that is collapsed by default. Click on it to expand it (that's what the arrow on the left means).
But can I use my own icon?
You will have to define a theme_print_format_link function which will replace the module's function with the same name and where you can indicate your custom-defined icon, and set the html element to true so that your image tag is interpreted as HTML. See the following for an example:
<?php
function theme_print_format_link() {
 
$print_html_link_class = variable_get('print_html_link_class', 'print-page');
 
$print_html_new_window = variable_get('print_html_new_window', 0);
 
$print_html_show_link = variable_get('print_html_show_link', 1);
 
$print_html_link_text = filter_xss(variable_get('print_html_link_text', t('Printer-friendly version')));

 
$img = local_path_to_your_img_file;
 
$title = t('Display a printer-friendly version of this page.');
 
$class = strip_tags($print_html_link_class);
 
$new_window = $print_html_new_window;
 
$format = _print_format_link_aux($print_html_show_link, $print_html_link_text, $img);

  return array(
'text' => $format['text'],
              
'html' => $format['html'],
              
'attributes' => print_fill_attributes($title, $class, $new_window),
              );
}
?>

Is it possible to place the PF link somewhere else?
Yes, but you have to take care of it. Disable the PF link in admin/settings/print and you're then free to place a link to print/nid or to print/path_alias wherever you want (such as a block or the node content). I recommend the following code to place the link, as it maintains the configurable attributes:
<?php
print print_insert_link();
?>

To insert a link to the send by email version:
<?php
print print_mail_insert_link();
?>

To insert a link to the PDF version:
<?php
print print_pdf_insert_link();
?>

Is it possible to change the styles used in the PF page?
You can always change them easily. You can either:
  1. Edit the print.css in the modules directory, or
  2. Define your own CSS with the appropriate styles and specify it in the module settings.
Is it possible to define a template for a specific content type?
Yes, the module will try the following locations for the PF page template:
  1. print_format.node-type.tpl.php in the theme directory
  2. print_format.node-type.tpl.php in the module directory
  3. print_format.tpl.php in the theme directory
  4. print_format.tpl.php in the module directory
  5. print.node-type.tpl.php in the theme directory
  6. print.node-type.tpl.php in the module directory
  7. print.tpl.php in the theme directory
  8. print.tpl.php in the module directory (supplied by the module)

format is either html, mail or pdf, and type is Drupal's node type (e.g. page, story, etc.)

I recommend that you edit the module's print.tpl.php to suit your tastes instead of creating something from scratch, as it is easier to remember the name of the members of the $print array and the names of the used styles.
Note that since you are creating your own template, if you want to use per-content-type styles, you can simply ignore the $print['css'] setting and hard-code your own per-content-type CSS file in your new template. Or you can define your own per-content-type styles to store in the configurable CSS file. Your choice!

I don't like the template used. Can I use another?
See the above question on how to do it (or you can always simply edit the module's print.tpl.php).
I am using a custom template but nothing seems to be working correctly. What's the problem?
Are you using the $node variable in your template? Be aware that the print module's template is not a normal Drupal template, so access to $node (among others) will not work. To fix this, place the following early in your template:
<?php
$node
= $print['node'];
?>

The blocks I have in the 'content' region are not showing up! Why?
First, if it is content, then it should be content.. Stuff placed in blocks is usually not content, and as such, should not appear in the printer-friendly view. That being said, if you really, really want it, add the following to your print.tpl.php template:
<?php
print theme('blocks', 'content');
?>

I see a lot of PHP warnings of the type: warning: array_map() [function.array-map]: Argument #2 should be an array in /home/site3/html/sites/all/modules/print/include/abstract_renderer.cls.php on line nnn
This is caused by a bug in domdpf's code. It is not possible to be fixed by this module. You can however edit line 42 of dompdf_config.inc.php to:
error_reporting(0);
dompdf or TCPDF don't work!
I don't maintain those libraries. Please check the libraries websites, and when applicable report the error to the author/maintainer:
Inline php script doesn't work in dompdf
dompdf supports inline php using the script type="text/php" for pagination, footers, and anything else you want to do with php. To enable it, be sure PHP is enabled in dompdf_config.inc.php and that this module's PDF setting "Auto-configure the PDF tool settings" is not checked (to accept values from dompdf_config.inc.php).
To test, copy one of the html examples that comes with dompdf into your print.tpl.php.
I am a themer / module author/maintainer. Is there a way to know when a node is being built by the print module so that I can disable some output?
Yes, if $node->build_mode evaluates to 'print', disable any output that is not suitable for a printable page.
How can I make the e-mail form show in a pop-up window?
Use the Popups module and set the e-mail link class to popups-form-noreload.
I have a problem/question not answered here. Where can I go for help?
Simply post a new issue in Drupal's issue system: http://drupal.org/project/issues/print
If possible, send me an e-mail with the link to your Drupal system where I can see the problem you are reporting.
Domdpdf doesn't like shorthand css?
Dompdf seems to have the best support for CSS, however it is very picky. It does not like CSS shorthand
font: italic small-caps bold 12px arial

It prefers explicit statements (font-family, font-size, etc). It also seems to prefer class selectors ("class=whatever") over id selectors ("id=whatever"). It does support page breaks via CSS
<div style="page-break-before: always;"></div>
Also, when rendering images, use CSS to correctly set the size.

How to setup Captcha?
This is fortunately easy due to the captcha module
http://drupal.org/project/captcha
Once installed you can click this setti
"Add CAPTCHA administration links to formsngs"
Now visit any send email form and click the link "Add Captcha" to this form.
Now choose the type you want and you are done!
How to add a gmap to a pdf?
Create a static Map using Google's static map function and insert it into your template.

/* Get your gmap_key from the gmap module variable */
$gmap_key = variable_get('googlemap_api_key', "insert_default_key_here");

/* Get a static image */
$staticmap_image = "<p align=center><img border='0' class='gmapimg' alt='Map'
                       src='http://maps.google.com/staticmap?center=" .
                       $node->location['lat'] . "," . $node->location['lon'] .
                       "&zoom=14&size=500x300&markers=" . $node->location['lat'] . "," .
                       $node->location['lon'] . ",blue&sensor=false&key=" . $gmap_key .
                       "' width=500px height=300px/></p>";

This example uses the location modules lat & lon to set the center and marker for the map. Google defines several variables to manipulate the map. The static map function will return a source image for you to use. Simply print it out in your print_pdf.node-mynodetype.tpl.php file.

The currently selected version of wkhtmltopdf () is not supported. Please update to a newer version.
If the status page fails to report the version of wkhtmltopdf then you likely need a version >= 0.9.6. If you already have a version >= 0.9.6 then this may mean that the Print module can not detect your wkhtmltopdf version. Try the following solutions:
  1. Make sure wkhtmltopdf library has executable permission, e.g. 755
  2. Check if proc_open() function allowed in your php.ini
  3. Try to disable SE Linux
How do I send a PDF by e-mail?
For sending a PDF via mimemail, this is how to call the print_pdf function:

<?php
  module_load_include
('inc', 'print_pdf', 'print_pdf.pages');  // require print_pdf.pages.inc

  // set up email
 
$recipients[] = email@example.com;
 
$subject = "Your PDF is attached";
 
$body = '<p>Your PDF is attached</p>';
 
$path = 'node/' . $node->nid;
 
$attachments[] = array(   // attach ticket
   
'filecontent' => print_pdf_generate_path($path),  // call the print_pdf function to generate PDF content string
   
'filemime' => 'application/pdf',
   
'filename' => $filename,
  );

 
// send email
 
mimemail( $settings['from'], $recipients, $subject, $body, FALSE, array(), drupal_html_to_text(decode_entities($body)), $attachments );
?>

Comments

PF Link Somewhere Else

Thanks for this great module. I have a question about FAQ #7 above. I have used the "print print_insert_link();" code from above and it works perfectly, creating the link exactly where I want it for several views on my site. The only problem is that when I do this, the link itself also appears in the generated "printer-friendly" page (something that doesn't happen with the module-generate link). Is there a simple "if" statement I could wrap around the code for the link I added that would check whether or not I'm actually in a printer-friendly view so I can skip over the generation of the link? Thanks.

EDIT: As a hack, I can make it work by using this:

if (strpos($_SERVER["REQUEST_URI"], "print") === false){
print print_insert_link();
}

which doesn't place the link if the url contains "print" in it, but it's rather inelegant and I'm hoping for a more-robust solution, if someone has one.

template, CSS and float property

Hello,

I wish to use a custom template. I try to display it in 2 columns but I don't success to do it.
Is the property float is take in consideration?

<body<?php print $print['sendtoprinter']; ?>>
   
    <div class="print-logo" style="background-color:#0FF; width:30%; height:12%; float:left;">
    <?php global $base_url;    ?>
    <img  alt="thre" src="<?php print $base_url; ?>/sites/all/themes/basic/images/logo_print.jpg" width="70%" />
    </div>
   
    <div class="print-adress" style="float:right; background-color:#0F0; width:65%; clear:none;">
    <p>Line 1<br />
        Line 2<br />
        Line 3
        </p>
    </div>
   
    <hr class="print-hr" />

The div.print-adress is displayed under the div.print-logo. What is the problem ?

Thanks for your help

How to add a gmap to a pdf?

How to add a gmap to a pdf?
Create a static Map using Google's static map function and insert it into your template.

/* Get your gmap_key from the gmap module variable */
$gmap_key = variable_get('googlemap_api_key', "insert_default_key_here");

/* Get a static image */
$staticmap_image = "<p align=center><img border='0' class='gmapimg' alt='Map'
                      &nbsp; src='http://maps.google.com/staticmap?center=" .
                       $node->location['lat'] . "," . $node->location['lon'] .
                       "&zoom=14&size=500x300&markers=" . $node->location['lat'] . "," .
                       $node->location['lon'] . ",blue&sensor=false&key=" . $gmap_key .
                       "' width=500px height=300px/>< / p>";

This example uses the location modules lat & lon to set the center and marker for the map. Google defines several variables to manipulate the map. The static map function will return a source image for you to use. Simply print it out in your print_pdf.node-mynodetype.tpl.php file.

In my case, (Drupal 6.16, Location 6.x-1.x-dev) i needed to change the variables for latitude and longitude in the above written code:

/* Get a static image */
$staticmap_image = "< p align=center>< img border='0' class='gmapimg' alt='Map'
src='http://maps.google.com/staticmap?center=" .
$node->location['lat'] . "," . $node->location['lon'] .
"&zoom=14&size=500x300&markers=" . $node->location['lat'] . "," .
$node->location['lon'] . ",blue&sensor=false&key=" . $gmap_key .
"' width=500px height=300px/> < / p >";

$node->location['lat']

and

$node->location['lon']

to

$node->locations[0]['latitude']

and

$node->locations[0]['longitude']

Replacing the icons with other images

Regarding the FAQ question and answer: "But can I use my own icon? You will have to define a theme_print_format_link function which will replace the module's function with the same name"

This wasn't very clear to me and might confuse others too. I took this to mean that I could create another copy of the theme_print_format_link function somewhere else, and I assumed 'template.php' in my themes folder. This is where I learned that PHP does not allow you to redefine functions. My first thought was to just modify the actual theme_print_format_link function (which is in the modules/print/print.module file, for anyone that would not instinctively know this) but then if the module is updated and the file overwritten then you lose your edit. Alternatively the modified version of this function could be placed in the themes template.php file and comment out the version in the print.module file. This way if the module is updated then PHP will complain about a 2nd definition of the function, which should remind you that you need to comment out the function definition in the module again.

This only helps with the print icon however, if you want to change the email icon then you can follow the same procedure with the 'theme_print_mail_format_link' function in the modules/print/print_mail/print_mail.module file. Similarly, for the PDF icon the 'theme_print_pdf_format_link' function in the modules/print/print_pdf.module file.

Hopefully, changing the icons will one day just be a setting, which would eliminate having to do all this.

I use my own icon? Im' using zen theme

Just to add, If you're using zen theme or similar themes you have to indicate the theme name ex. YOUR_THEME_NAME
for image you can use this snippet $img = path_to_theme().'/images/MY_NEW_PRINT_ICON.png'; where your MY_NEW_PRINT_ICON.png file is under images folder(considering you have images folder inside your theme).

<?php
function YOUR_THEME_NAME_print_format_link() {
 
$print_html_link_class = variable_get('print_html_link_class', 'print-page');
 
$print_html_new_window = variable_get('print_html_new_window', 0);
 
$print_html_show_link = variable_get('print_html_show_link', 1);
 
$print_html_link_text = filter_xss(variable_get('print_html_link_text', t('Printer-friendly version')));

 
$img = path_to_theme().'/images/MY_NEW_PRINT_ICON.png';
 
$title = t('Display a printer-friendly version of this page.');
 
$class = strip_tags($print_html_link_class);
 
$new_window = $print_html_new_window;
 
$format = _print_format_link_aux($print_html_show_link, $print_html_link_text, $img);

  return array(
'text' => $format['text'],
              
'html' => $format['html'],
              
'attributes' => print_fill_attributes($title, $class, $new_window),
              );
}
?>

-------------------------------
personal | blogspot | wp

Using $node->build_mode = print

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;
     
  }
}
?>

E-mail Design

How can make custom design to mail page when it send to any mail without change the print page design

This can't be right

To change the styling, it says "Edit the print.css in the modules directory". Am I missing something or is the documentation recommending that users hack the module to change CSS?

google static maps

The documentation about inserting an static map in th pdf file needs to be updated.
Google static maps no longer require an api key, Is there any work around for this?

CSS not working in PDF

In this module I am creating custom changes (like set footer sticky in bottom and trying to generate PDF only in 1 page) with CSS but in PDF, CSS not doing anything.. Can anyone help me...?

Is there was a way to specify

Is there was a way to specify elements that you don't want printed (like the print links), but still want on the page?

About this page

Drupal version
Drupal 4.7.x, Drupal 5.x, Drupal 6.x, Drupal 7.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