I have a custom module with some form fields. I want to submit this form and generate pdf file of user filled values in new tab. I am trying with TCPDF but it doesn't display any fieldset ( as border ).

In submit funciton , I am taking $form array and using drupal_render($form) that render form values as html ( if I print ). If I pass this html to WriteHTML($html, true) , it gives pdf but there is no styling left on that form.

3 Answers 3


Have you tried Webform2PDF?

The Webform2PDF Drupal module is an extension of the Webform module. It can be used to generate PDF document from the results of a form. The generated PDF document can be attached to the form summary e-mail sent by Webform module, or it can be downloaded from the /Results/ page. Different PDF templates can be set for each form. The templates can be formatted with HTML tags, and they can be edited with WYSIWYG Drupal module, making the template creation easy and the templates highly customizable. The output documents will be created by using these templates.

  • For me , Webform2PDF only shows token '%email_values' and not the submitted values. It seems to print the values filled by user in different format (by taking from database). I want to use existing form values. I have some form fields in disabled state so I will not get those in $form_state['values'] or $form_state['input']. I submit this form to webservice, so there is no possibility to recall user submitted values. My goal is to generate pdf similar to form layout. I want to avoid using any theme function until it is necessary. Thanks for the answer.
    – atyagi
    Jul 24, 2014 at 13:25

TCPDF doesn't support all styling attributes.It only supports some of the features that are given below.it has a very limited CSS support.


Basically, You can use tables to style your pdf data And styling pdf throught table attributes.like



And Note That PDF and HTML and different formats that hardly have anything in common. If TCPDF allows you to provide input data using HTML and CSS it's because it implements a simple parser for these two languages and tries to figure out how to translate that into PDF. So it's logical that TCPDF only supports a little subset of the HTML and CSS specification and, even in supported stuff, it's probably not as perfect as in first class web browsers.


The Views Pdf module will do everything that you need.

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.

  • Should I make view from custom form? Is there any solution that can be used in custom module form?
    – atyagi
    Jul 24, 2014 at 13:33
  • Yes make a view (block, page, etc...)that incorporates the fields from your custom form, then add a 'PDF' page version of the view, you can then position the fields on a PDF page. I use this with entityform and it works very well. Jul 24, 2014 at 15:38

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.