With the Views PDF module you can output a view as a PDF document. Each field of the view can be placed on the PDF page directly in the administration interface. Therefore a new display called "PDF Page" is added.
There are already some PDF solutions such as Print. But these solutions use the HTML output and converts this to PDF. The disadvantages of such an integration are:
- No control over page flow (e.g. page break).
- Little or no control over page header and footer.
- You need HTML skills to change the layout.
- The rendering is slow and need a lot of memory, because it need to render the HTML.
- Complex tables make troubles.
- Vector graphics can not be implemented, therefore the printing of the document can be problematic.
- You are limited by HTML's capabilities.
Installation
Installation instructions:
- Download the module or checkout the module.
- Upload the module to your Drupal instance.
- Download the required libraries. Download TCPDF and FPDI.
Recomended versions: FPDI 1.4.4, TCPDF 6.0.020, FPDF_TPL 1.2.3 - Copy the files to "sites/all/libraries/" directory in the Drupal directory into their own "fpdi" and "tcpdf" sub-directories and include "fpdf_tpl.php" in the "fpdi" sub-directory.
- Set up a view with a PDF display.
- Use it.
About jQuery Update
jQuery Update is only required for Views UI to upload templates. It only needs to be set to version 1.5 or higher.
As of jQuery Update 7.x-2.5 the jQuery version can be set as low as 1.4.4, the default version for Drupal 7. Also, admin pages can be set to use a different version. Views PDF only needs the admin pages to be set to 1.5 or higher. Once your views are created, you can change the settings to whatever version gives you best compatibility with the other modules on your site.
Basic Usage
- Create a new view or use an existing view. New to views? See the documentation of the Views module.
- In the view add the display "PDF Page".
- Select the new added display.
- Select the Style. You can use PDF unformatted to place the fields in no structured way on the PDF. Use PDF table to place the fields in table with a table header.
- In the settings of the style you can set up per field settings such as the position, the size of the field, the font and so on. Important: Switch to the "PDF Page" display in order to see these options; they don't appear in the "Defaults" display.
- Under PDF Page Setting you can set up the size of the page.
- Under PDF Font Settings you can set up the default fonts for the PDF.
- Under PDF Template Settings you can set up a background PDF.
- To add a page break, you can add a PDF page break field. When this field is rendered new page is added. Reorder the fields if necessary.
- You can find also a page number field. You can use it to print the current page number. To position the field in the header or footer, set the relative position in the field settings to "In header / footer".
Unformatted Style
Positions
You can position fields relative to
- The page: The field is positioned to the page left top, left upper, right bottom or left bottom corner. Depending what you select by the corner setting.
- The footer / header: The field will be repeated automatically in the footer / header.
- The last writing position: The position of the writing head will be unchanged.
- Itself: The first time the field is written to the PDF, the last writing position is used. (used for multiple nodes)
- Another field: You can select any earlier written field to use as the relative position.
All these positions can be modified by adding a x resp. y coordinate. These coordinates were added to the position selected by the above relative position. The default unit for these coordinates is millimeters, but that can be changed under "PDF Page Settings" (choose between point, centimeter and inch). In the fields themselves, just write numbers (no unit).
Text Settings
Here you can select the text settings for the field. This settings overwrites the default values, which you can specify under "PDF Fonts Settings". Here you can read how you can create additional fonts. Place the font files in the directory "lib/tcpdf/fonts".
Render Settings
In the render settings fields you can add additional settings which were not covered by the GUI settings above. With "$this" you can access the TCPDF API. Additional there are the following variables:
$w = // width
$h = // height
$border = // border option, see the TCPDF documentation about this option
$align = // the alignment
$fill = // fill the cell acceptable values are true or false, use $this->SetFillColor() on next line to set color of fill
$ln = // position after
$reseth = // reset the hight
$stretch = // character stretch
$ishtml = // html is rendered / or not
$autopadding = // set the padding automatically
$maxh = // set max height
$valign = // vertical alignment
$fitcell = // reduce the font size if the text does not match into it
$content = // The content of the field
For example this can be used to transform the fields text to uppercase:
$content = strtoupper($content);
You have the option to use the API before the field is printed out with MultiCell and after the field is printed. Normally you can use the second one to reset the previous changes.
Important: The entered code must be valid PHP code. Note that in the PHP Code fields the <?php and the ?> delimiters are not needed.
Table Views Style
To print a table in the PDF you can use the table view style. There you can specify for each column a header formatting and the table body formatting of this field. The options are very similar to the unformatted options. In contrast to the unformatted style, you cannot position the fields complete free on the PDF, you can only set the row height and the width of the cell.
But the table itself can be positioned totally free on the PDF. If the page end is reached, a page break is automatically inserted.
Hyphenation
The hyphenation is implemented by the TCPDF library. To use hyphenation you need to download the Tex patterns and save them in "hyphenate_patterns" in the TCPDF library folder. The patterns can be found here.
PDF Templates
Normally you want also to print static content on the PDF such as a company logo or an address. To simplify this process a so called PDF template is added. This is a normal PDF file which contains all the static content. The dynamic content (view fields) will be printed on this PDF.
You can setup such a file per row or for the whole page. The per row file make sense if you have for example for each node a different background or if you want to combine multiple backgrounds. The background could be also a file field. This enables the option to change the background per row.
Additionally you can setup also a leading and a succeed template file. This pages will be added without printing on it. This is useful if you want to add the general terms and conditions in your PDF invoice.
Append and Include other Views
There are two additional modules included in the Views PDF module. One is to append a view and the other is to include a view. Append means that the referenced view is appended to the current view. Include means that the referenced view will be added as a field to the view.
With these modules you can implement much more complex PDF's. For example if you want to add the invoice lines to your invoice it can be hard to implement this by a single query. If you split this in a "invoice" query and in a "invoice line" query, the task becomes very easy. You can add the invoice lines as a table in a separate view trough the include field module. See the next paragraph for more details about this.
Use Case 1: Invoice for Ubercart
A typical use case for PDF's is the invoice. Most customers especially in B2B want a PDF invoice. Ubercart does not provide such a invoice. There exists a module for invoice generating. The approach of this module is to generate from HTML the PDF with DOMPDF. This is a nice library, but consumes much RAM and it takes some time to generate the PDF. Additionally you can control the layout only be HTML. It is also not integrated with Ubercart.
The module Ubercart Views provides an interface to the Ubercart order and order lines. In combination with this module you can create directly PDF invoices. Therefore you need to add a new order view. This builds the main invoice. There you setup the address, the invoice header (order id, order date ...) and the order footer.
You can then add an order line view with the PDF table style. This order line view can then be included in the invoice view.
The Ubercart PDF Invoice project is implemented as above described.
Use Case 2: Print at Home Solution
A common problem with the Signup module is, that you want providing a ticket as PDF for your customers. This module can help you to produce such a PDF.
Here you can find a demonstration of the use case:
http://pdf.use-cases.customweb.ch/
This use case consists of the Signup, Ubercart, Ubercart Signup Integration and some custom code (integration of Ubercart Signup with the Views module).
The approach is very similar to the first use case. If you can access the data with a view, then you can generate the PDF.
You setup a new view with the "signup" entity as the base. Then you join all the relevant information to this entity. Add the required fields and put it on the PDF.
Troubleshooting empty pages when including other Views
If Views PDF is used with an inserted view and that view is the last field before a page break, then the page break should be aligned "top left" to the "Page." Otherwise, it can happen that either empty pages or an overflow of the included view to the next page occur.
In case of not using any page breaks, but the inserted view is still the last field on the page and an empty page occurs at the end of the PDF, aligning the Inserted View field to "Last writing position" instead of the previous field may help.
Comments
no query was run
When I create a PDF page and I want to view the PDF I get an empty PDF page.
If I want a preview the message is: No query was run.
Could you help me, what is the problem?
Regards
A similar post was posted
A similar post was posted here: http://drupal.org/node/1217708
Basically, you need to define the layout of your view accordingly.
T
Cant have it working
I wished somone was more specific. No matter what I do, I get an empty pdf.
Try setting the font size on
Try setting the font size on the fields. I set 12 for example and it started working.
yes, set the PDF Field
yes, set the PDF Field setting Font Size for glory
--
http://drupaltees.com
80s themed Drupal T-Shirts
I tried to set anything for
I tried to set anything for every field, but still getting an empty pdf.
Saigon... shit; I'm still only in Saigon.
Solved
For me the solution was this:
http://drupal.org/node/1513490
I enabled php filter module and it started generating pdfs.
Saigon... shit; I'm still only in Saigon.
Print out Pages
I have a website where I sell downloadable paper models.
I have instruction pages formatted like this.
Could I use this module to create a pdf version of the page which users can download?
Thanks.
Did you use ViewsPDF?
Hello, I've checked your blog/link, and the whole idea of the paper figures is awesome. I was wondering, did you finally used ViewsPDF on your site?
Best,
PHP tags
Please beware wrapping the render settings in PHP tags. You will get nasty PHP errors syaing header already sent.
So if you want to add a border ( say ) enter :
$border = 1;
rather than :
as the doc could be interpreted as suggesting.
RE: PHP tags - borders
This does not work for me. There are no errors and no borders. I have tried placing it in the before and after render fields for the header and body styles. So far no luck.
Update: it would seem that the borders do work as long as a template PDF is not being used for the background. Would anyone know if this was due to the PDF file itself or in the ViewsPDF code?
Cybermache I am using both a
Cybermache
I am using both a template PDF as a background and successfully seeing borders ........
Good luck.
Making template background transparent works
After accidentally finding the cells underneath the PDF template image while editing the file in Illustrator, I made the PDF template background transparent and finally got the cell styles to be part of my print out. I posted about this on the issue tracker since it doesn't seem intuitive to me, but I could just be wrong about that.
Sorting problem, also 'save as' file name
I've found this module to be very successful with a couple of exceptions.
I have two sorting criteria and while the first one is grouped together the sort order isn't respected. The other issue is the default file name, I can't find how to change that anywhere. You can see the result here:
http://www.ammalux.com/catalogue-pdf
The first sort is on the field 'category' (which is labelled) and the second is on the 'title' field, which is the main heading at the top left (between horizontal lines.)
The default file name is 'product_header' which I can't even find anywhere as a label!
Hoping someone can help.
*edit*
Changing the sort order from ascending to descending does change the direction of sort, but it's still not alpha sorted. The title field (second level sorting) works fine.
file name customization
hi,
Have you found a solution for customizing the filename ?
I found for firefox, but for IE its not working....
Thanks,
Sanjithkumar.V
svnindia
where do i find fpdf_tpl.php
Hello everybody,
maybe I am to stupid, but where do I find the fpdf_tpl.php?
Thanks for your help.
Best regards,
Alex
The fpdf_tpl.php is in the
The fpdf_tpl.php is in the second download under the link
http://www.setasign.de/products/pdf-php-solutions/fpdi/downloads/
PHP Warning
Hello, I use the Views PDF module to obtain a PDF from a set of nodes, and I include a cover using PDF template. When a PDF is downloaded, an error (or warning) is shown:
Notice: Undefined offset: 1 en FPDF_TPL->getTemplateSize() (line 239 of #folder#/sites/all/libraries/fpdi/fpdf_tpl.php).
The PDF is generated and downloaded, but I don't understand this error and I can't fix it.
Thank you!
#folder is a path of my site
I have this this
I have this this errors
Strict warning: Declaration of FPDF::_putstream() should be compatible with that of TCPDF::_putstream() in require_once() (line 17 of /opt/lampp/htdocs/rportal/profiles/drop_jobs/modules/views_pdf/views_pdf_template.php).
Strict warning: Declaration of FPDF_TPL::AddPage() should be compatible with that of TCPDF::AddPage() in require_once() (line 27 of /opt/lampp/htdocs/rportal/sites/all/libraries/fpdi/fpdi.php).
Strict warning: Declaration of FPDF_TPL::SetFont() should be compatible with that of TCPDF::SetFont() in require_once() (line 27 of /opt/lampp/htdocs/rportal/sites/all/libraries/fpdi/fpdi.php).
Strict warning: Declaration of FPDF_TPL::Link() should be compatible with that of TCPDF::Link() in require_once() (line 27 of /opt/lampp/htdocs/rportal/sites/all/libraries/fpdi/fpdi.php).
Strict warning: Declaration of FPDF_TPL::Image() should be compatible with that of TCPDF::Image() in require_once() (line 27 of /opt/lampp/htdocs/rportal/sites/all/libraries/fpdi/fpdi.php).
Any solutions? or am I missing something? Please help
Also an empty PDF is
Also an empty PDF is generated
Are you running PHP 5.4? I
Are you running PHP 5.4? I started getting these when I switched to 5.4. I get these all the time, and everything works fine. If you're getting a blank page, it could be for another reason.
Installation Problem with VIEWS PDF
Hi,
am using Drupal 7, am trying to using PDF Page,
when am adding the PDF Page, am getting validation error like
"Display "PDF Page" uses a path but the path is undefined."
Please any one can help me to solve this error
Thank you
Elan
@Elan - That's just Views
@Elan - That's just Views telling you that you are creating a "page" display but you haven't given it a path yet. It is unrelated to Views PDF. Just provide a path and the message will go away.
-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com
path?
This sounds like a great answer. Can you please state where to add that path.
It's in the middle column,
It's in the middle column, when you are editing the View. Right under "Page settings".
(This only applies to Page displays. Blocks don't need paths.)
-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com
Still have Display "PDF Page" uses a path but the path is undefi
I tried putting a path into the path area, but the error message is still there. This is when I am creating a PDF page. Not sure how to get rid of the message.
not working
FWIW, This doesn't work for me. I'm on On 7.31, have a basic view showing me content of a node. When trying to set this up, I get the same "Display "PDF Page" uses a path but the path is undefined." error others report. There is a path defined (since the view already exists and I'm just adding another display to it, yes?), and am still getting the message. Changing the path to another doesn't resolve the error.
You have to define a separate
You have to define a separate path field for the pdf display. If you already have a view, and then add a pdf display, you will then also need to click on the pdf display, and define a separate path on that display as well. If you have two displays both pointing to the same path, you are doing something wrong. If you don't have the path defined within the pdf display, you are also doing something wrong. Hope that helps.
error is showing specifically
error is showing specifically for "pdf page" display though path is set for other page display that was added when view is created.
Display "PDF Page" uses a path but the path is undefined.
Should we have to set dummy path for this display?
I have the same issue. when I
I have the same issue. when I try to add the 'PDF page', I see WSoD and when I navigate back, it shows me that error message.
Check this issue: https://www.drupal.org/node/2546872
Regards.
🪷 Beautifulmind
Include a field to only be output once
I want to add a header to my views pdf but I don't want it to repeat for every row or for every page. Any way to do this?
Adam Young
Vancouver, BC
http://www.adamtyoung.ca
Try using a PDF template.
Try using a PDF template. Create a PDF file with desired header, upload it on PDF settings and the same will be used for each page created of your PDF.
Regards.
🪷 Beautifulmind
page break on group
I have made a view on CiviCRM contacts grouped by a certain field.
Now I'd like to generate a PDF where each group starts on a new page.
How can I achieve this?
I just need a printable format, PDF is not a requirement so if there is a module more suited to do this please let me know!
Thanks
Hey there,
Hey there,
I'm have the same issue right now. Can you solve it?
Well... please let me know.
Cheers
diference between documentation page and issue
hello you all
i am going to collaborate to betatest and make documentation for this module during agost. killua99 is one of its maintainers and also he is going to work in agost to try to make it much better.
it would be a good collaboration that you well use the documentation page and the issue cue as is accorded in drupal.
documentation has the intention to teach to use the module and anybody can write what is not written jet, as well as explain tips and tricks, links to videos or any solution to a problem.
issue has the intention to work with bug reports, tasks, feature requests and support requests.
if you have doubts or are not used to use the issue cue, please read the excellent documentation that has been made to help you and the project.
drupal is a collaborative project, then as soon as you write something in the site, you are collaborating :)
if you learn where to put your work, it will be better used and we all take advantage of that.
i think this is a very good module that with some work it will make as easy to make pdf from views. so please, share your experience with us and be part of the team.
also, we need someone with good english that will correct our english and facilitate the communication with people consulting this documentation.
so you are very welcome! :)
//trying to answer one question for each one that i make.
//this way, drupal will be more friendly and strong
View PDF
Hi,
I'm a little confused by the directions for the View PDF. I appreciate that the instructions are lengthy and detailed, however I have a few questions because I am unable to get this working.
1. What do you mean when you say add the display "PDF Page"? I know what a view is and have developed many of them. But I just don't know what "display" you are referring to. Do you mean a content type?
2. I have created a view called PDF Page. When I test the page, I don't get any PDF links or see anything related to PDF. Help?
3. Where do I select style, PDF unformatted, PDF tables, etc. these are not showing up on the View which is called PDF Test. None of these items show up on the PDF test or PDF Page.
I'm sure I have something incorrectly configured - I would appreciate any help with understanding the instructions and fixes.
THANKS!
Deb
What do you mean when you say
It is not a content type but rather it is a views display type which is under views Add button. It will be only available after you enabled the module "Views PDF Display".
Once you add it into your view you can get the style settings changed and get access to styles under format section of views.
View PDF Display
Hi nithinkolekar -
Thanks for the response ! I don't see "Views PDF Display" under Add in the View. I have verified that it is enabled in Modules.
I have the view setup very simply.
Format: Unformatted List | Settings
Show: Fields | Settings
Fields ->Add (no Display PDF View)
Filter Criteria
Sort Criteria
Installed to libraries as instructed:
TCPDF
FPDF
Thanks again - please help
Deb
View PDF Display
Ok - I got it. A little slow here. I see that I'm to add a new page and from the drop down select "PDF Page".
However, now all I get is a blank screen -
Many thanks for your help
Deb
could you please create an
could you please create an issue or follow issues which are already addressing blank screen. There you can upload screenshots , share info like version etc.
troubles empty values
i also have a problem with an empty pdf page.
but my problem is different then yours.
i linked my question :
https://www.drupal.org/node/2877675