Print: 5. Frequently Asked Questions
Questions
- I have enabled the module, but the PF page link is not showing up!
- The Printer-friendly version in book nodes is not working correctly.
- The book pages still display the text "Printer friendly pages," and no icon
- Can I replace the 'Printer-friendly version' link with an icon?
- I can't see the icon-only option!
- But can I use my own icon?
- Is it possible to place the PF link somewhere else?
- Is it possible to change the styles used in the PF page?
- Is it possible to define a template for a specific content type?
- I don't like the template used. Can I use another?
- I am using a custom template but nothing seems to be working correctly. What's the problem?
- The blocks I have in the 'content' region are not showing up! Why?
- 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
- dompdf or TCPDF don't work!
- Inline php script doesn't work in dompdf
- 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?
- How can I make the e-mail form show in a pop-up window?
- I have a problem/question not answered here. Where can I go for help?
- Domdpdf doesn't like shorthand css?
- How to add captcha?
- How to add a gmap to a pdf?
- The currently selected version of wkhtmltopdf () is not supported. Please update to a newer version.
- How do I send a PDF by e-mail?
- Does the module support views?
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):
- Make sure that the module is enabled (the check-box next to 'Printer-friendly pages' and 'Printer-friendly pages UI' in admin/build/modules must be ticked).
- 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).
- In admin/settings/print, make sure that you have enabled the PF link.
- For each content type x, check in admin/content/types/x that the 'Show printer-friendly version link' is enabled.
- If you're trying to render your nodes within panels, you'll to have
add the printer-friendly links to you panel, from under Miscellaneous.
- 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?
-
The example below is for the 6.x-1.x and 7.x-1.x branches. In 7.x-2.x the theme function is theme_print_ui_format_link.
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: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:
print print_insert_link();
To insert a link to the send by email version:
print print_mail_insert_link();
To insert a link to the PDF version:
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:
- Edit the print.css in the modules directory, or
- 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:
Drupal 7:- print--format--node--type.tpl.php in the theme directory
- print--format.tpl.php in the theme directory
- print--node--type.tpl.php in the theme directory
- print.tpl.php in the theme directory
- print.tpl.php in the module directory (supplied by the module)
Drupal 6:
- print_format.node-type.tpl.php in the theme directory
- print_format.node-type.tpl.php in the module directory
- print_format.tpl.php in the theme directory
- print_format.tpl.php in the module directory
- print.node-type.tpl.php in the theme directory
- print.node-type.tpl.php in the module directory
- print.tpl.php in the theme directory
- print.tpl.php in the module directory (supplied by the module)
format is either html, mail, pdf or epub, 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:
$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:
Drupal 6
print theme('blocks', 'content');
Drupal 7
print render(block_get_blocks_by_region('content'));Drupal 7 when using Context module to assign blocks
if ($plugin = context_get_plugin('reaction', 'block')) : print render($plugin->block_get_blocks_by_region('my_region_name')); endif;If you are displaying aspects of the content in blocks (for example using the Field as Block module), another way to handle this is to enable the Print display mode and disable the Field Blocks in that.
- 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:
- TCPDF: http://tcpdf.org
- dompdf: http://code.google.com/p/dompdf/wiki/FAQ
- 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_modeevaluates 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 arialIt 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:
- Make sure wkhtmltopdf library has executable permission, e.g. 755
- Check if proc_open() function allowed in your php.ini
- Try to disable SE Linux
- If you are using the static binary, ensure you have the correct version (i386 or amd64). e.g. The i386 binary fails to run on 64bit Ubuntu, but does not generate errors
- How do I send a PDF by e-mail?
-
For sending a PDF via mimemail, this is how to call the print_pdf function:
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->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 ); - Does the module support views?
-
Simple answer: Yes!
Complex answer: Probably
The module supports views, the same way that it supports any other system-generated page: it asks Drupal to render it and uses that content. However, by definition non-node pages do not have a links area, so it's a little more complicated to display the link to the printer-friendly versions. The module provides two options for this: the blocks area and the help area. To use these, you need to add your Views page path to the system-generated pages list in the module's settings pages.
If you don't like these options, you can still insert the links yourself by calling the print*_insert_link() functions as PHP code as Views fields or in the header or footer of the view.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion