Tips to make awesome PDFs

Tuesday, Aug 5, 2014

You can use the HTML editor to create templates that can then be converted to PDF. Not all your best efforts immediately transfer to a masterpiece in PDF however. When designing PDF templates keep in mind that the conversation from HTML to PDF by the TC PDF generator needs basic HTML. You will need some basic HTML coding experience as you are unlikely to be able to create robust PDF templates without editing the HTML code directly. Here are some rules:

  • If divs don’t work when Try to use tables, not div tags for alignment and spacing

  • Clean or avoid copying and pasting from a word processor document or a web page

  • Don’t use complex HTML encoded entities eg. ½

  • While most style tags are supported keep your HTML simple, using older style codes like <i> and <strong>

  • Stylesheets are not supported, all styles must be defined in the template

  • Here is an example of what you can do and here is the HTML/PHP that produces this example

HTML Purifier

We use HTML Purifier to ensure that the HTML code entering our PDF generator is standards compliant and therefore will result in less errors. Remember the PDF generator we use generates the PDF from HTML. You might get away with some sloppy coding in HTML but when converting to PDF you won’t. For example, if you enclose a table with text in <small> </small> the text inside the table will appear small in a browser, but HTML purifier will convert the whole table to just plain text (thinking “Hey <small> is a tag for text, silly person accidently put <table> in here - I better remove it!”.)

Tables for layout

An A4 page usually formats well if a table is 600 x 800. eg. <table style="width: 600;" border="0" cellspacing="1" cellpadding="5">

Including footers and headers

  • If you wish to include the footer and header you need to do so within the constraints of the table size, if you make the table too tall then the PDF generator may fail.

  • You will need to create the header and footer for each page

  • Page numbers will not be created automatically - these need to be entered manually.

To create multiple page PDFs

Where you want the new page to start you need to include the following code: <tcpdf method="AddPage" />, for those interested in the technical aspect of this please read this.

Page orientation and size

Currently the PDF generator only supports Portrait not Landscape orientation, and A4 paper size.

You can include links and images, although some tags used for formatting might not work

Also see;

Troubleshooting

If you are having problems with the PDF not being attached to the email you don’t have a PDF template content issue but some missing configuration.

If you have a blank PDF attached to the email then your configuration is correct, but the PDF content is preventing the PDF generator from creating the PDF, one strategy is as follows:

  • Start with a completely blank PDF then add just text, no fields nor HTML styles.

  • Copy across a small section (1/4 of the total) of content from the offending PDF template eg. the header or table (without any body content)

  • At each incremental change send an email to generate the PDF to monitor progress, looking for when the PDF goes blank, reversing the addition and repeating the gradual addition.

  • Continue making this change bit by bit, to work out what might be stopping the PDF from being generated.

It is always useful to have test ‘blank’ content available to rule out where the errors are occuring, so have a ‘blank’ course description, residential description, etc to help ascertain if the error is with the template or content, and if it is content, which content. The ‘blank’ content includes just the words ‘blank’ - plain text is the least likely offender to upset the PDF convertor.

Note
Keep in mind that the content in the replaceable variables may also cause the PDF to fail. In particular considering checking the content types if they are used in your PDF template: promotional, course descriptions, residential descriptions, topic descriptions, venue descriptions.
Note
To troubleshoot content issues you may wish to remove all replaceable variables to then add one at a time to confirm the PDF generators works as expected.