5

I would like to theme the PDF generated through the Print module. I have created a view for displaying the fields of my choice in PDF.

Can anyone help me out on how to theme the PDF?

1
  • Anyone knowing the answer or having some idea about it. It is urgent.
    – Sabreena
    Feb 18, 2014 at 14:15

5 Answers 5

2

Create your own template file:

print[--html|--mail|--pdf][--node--node-type].tpl.php

Look inside the modules directory and you will see the template files, say print.tpl.php. Copy these and modify as needed.

2
  • I copied print.tpl.php inside my theme directory, and modified as per the need. The thing is I want to theme each fied of a view (view is created for user-profile). As of now I am able to theme the whole content, not the individual fields. How can I retrieve each field of user-profile view in print.tpl.php.
    – Sabreena
    Feb 20, 2014 at 4:47
  • So the pdf is actually printing the data from a view and not the node? Feb 20, 2014 at 17:55
2

You should use Views PDF module

With this 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" is added.

0
1

I did the same thing recently: I had a view on my nodes page that outputs fields, including fields from a referenced node, but of course this was not included in the default PDF file output by the Print module.

What I did was:

  • Making a custom template as Chadpeppers explained. The filename should have a name like print[--html|--mail|--pdf][--node--node-type].tpl.php; in my case, it was print--pdf--node--job.tpl.php.

  • Embedding the view I needed in the template, using the current node ID as argument.

     $view = views_get_view('VIEW_NAME');
     $view->set_arguments(array($node->nid));
     $view->execute();
    

I now have a view object with all the results I expected.

1

You could use the FillPDF module and plug your data into a pre-designed fillable PDF.

Most PDF modules generate PDFs from scratch; FillPDF is not one of those modules. Instead, it lets you fill in existing editable PDFs with data from your Drupal site. Editable PDFs are those forms that let you type into them

1

I agree with @Rupesh. You should use the Views PDF module. First create the view, add the fields you need, take full advantage of theming, then add a PDF display, which this module provides. This is easier than theming the print module IMO.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.