Views PDF Gotchas
The purpose of this handbook page is to augment Views PDF main documentation handbook page with a little troubleshooting and gotchas. These are gathered from comments, issue queue, and experimentation. Please feel free to add your own and remove them as the UI evolves!
Field Formatters
The documentation makes mention of Field Formatters. These are not found on the field settings itself but rather on the PDF Display Settings. Each field requires some basics, and at minimum the font size and position need to be set. For starters, why not "12" (without units) for size on each field. For unformatted, try "
Note that these field settings are separate for PDF as a Table and PDF Unformatted. Toggling back and forth between the two Display Styles seems to preserve per-field settings only from Table to Unformatted, not back again.
CSS Formatting
Applying CSS to format a PDF file is certainly not straightforward, because you never know, which properties are supported (look at examples may be helpful) and you can't use something as Firebug to debug your code. The second limitation can be worked around by following these steps (adapted from post by gillarf):
- Make sure you have the last version of views pdf
- Create your view with a page display.
- Create a CSS file for PDF inside your theme directory and reference it from your theme's info file. Don't forget to clean theme cache (look at https://drupal.org/node/171209 for details).
- Try to set some basic styles (font properties, border...) for your content and verify, that they're correct.
- Create your PDF display in views. For position of fields use the views UI format settings (under PDF fields).
- Add the path to your CSS file in your view under PDF Settings. Start from your Drupal root directory and do not have a slash at the beginning (result should be like
sites/all/themes/[mytheme]/[css]/[print.css]. Replace text in brackets by your correct values. - Don't forget to remove the pdf.css file from your theme info file.
Adding classes to fields
Adding classes to fields using the Style settings UI won't work for Views PDF. Instead use Rewrite results > rewrite the output of this field. Try something like <div class="myclass">[field_my_field]</div>
You can add classes or tags to field labels, simply by adding them to the label field e.g. <strong>[label]</strong>
Inline images into body - Insert module
If you place inline images into body, or any other text field, with <img> tags, be sure that into the "src" attribute you use the FULL PATH to the image file,
<img src="http://www.example.com/drupal/sites/default/files/image.jpg" [...] --> correct
--> wrong<img src="/sites/default/files/image.jpg" [...]
or else your image will not be printed into the pdf.
When using Insert module be sure to enable full urls:
Structure > Content types > [content type] > Manage fields > [image field] > edit > check "Use absolute paths"
Templates
PDF templates: PDF templates can be added in Row style options (under Format -> Show -> Settings) Here you have options to add Leading PDF Template (to be printed in front of every row), Template PDF (a PDF file on which the content is printed), and a Succeed PDF Template (to be printed after the main content).
Views Templates: Traditional Views templates (.tpl files) are not respected.
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