M4 PDF Extensions module replaces the built-in PDF document generation and adds new options for document creation in the administration through user templates. All with full support for UTF-8 encoding and with the possibility to use non-latin fonts.
The module operates in two modes. The two modes differ only in activation. They use the same data source and can use the same templates. In the first mode, PDF documents can be created in the administration module.
In the second mode, a PDF document is created as a replacement in one of the 8 options for creating PDF documents in PrestaShop™. These options can be individually selected in the module configuration.
The following diagram shows how to activate and create PDF documents. The first step is to gather or select the desired data. Data is loaded into the selected Smarty template. The template processes the data and generates a HTML page that is transferred to a mPDF library, which creates a PDF document.
More information on the libraries used:
Smarty - http://www.smarty.net/docs.php
mPDF - http://mpdf1.com/manual/
There are 5 sources of data. These correspond exactly to the selections in the module configuration. The module can work with this data and create outputs:
All data sources provide a log list. For itemized orders and credit notes, related items are also available. This can be used to generate invoices, delivery slips and credit slips.
Templates mean Smarty Templates. It must be a fully featured HTML document with <head> and <body> tags. Templates are located in the subdirectory /tpl of the module. The module includes a tuning template and a testing template. These can be used to get started and familiarize with the template features.
The template can have 4 basic elements. Individual elements are highlighted in this simple template example.
To identify a template and determine whether it can be used with a particular data source, each template must contain a reference to name and data. The element name is the name of the template. The element data describes the data source for which the template is intended. Valid data sources are:
and
Marking the template with the elements name and data must appear at the beginning of the template as an HTML comment line (prepended by <!-- and -->), not on more than 5 lines.
The second component of the sample refers to the Smarty {assign} function, which assigns a value to the template variable. This part is optional. Even if you wish to use the Smarty function, you do not have to place it here. We mention this possibility because this is a well structured location to place constants or other code.
For a clear style definition, it is best to use CSS. The CSS style block must be enclosed within double tags {literal}<style> and </style>{/literal}. Style definition is not mandatory.
Rule @page defines page layout, orientation and edges. This and other supported rules are described in the mPDF library manual and on the User's Guide >> CSS & Stylesheets >> Supported CSS page.
The actual template content is located between tags <body> and </body>. Besides text, you can use tables, images, form elements and format the content using HTML tags and CSS. Their overview can be found in the mPDF library manual and on the User's Guide >> HTML support >> HTML Tags page.
The mPDF library can be used to add elements to the final document that cannot be created using standard HTML tags. In order to accomplish that, it uses its own tags. Some of them are the following:
All tags are described in the mPDF library manual and on the Reference >> HTML control tags page.
PrestaShop™ administrative tools can be used to translate multilingual texts. Select Tools >>Translations in the administration panel, in block Modify translations select Module translations and choose the language for translation.
All the PrestaShop™ modules for translation will appear on the next page. They include all the templates, as well as the administrative interface of the module. For easy identification of the templates, a common prefix, such as m4 should be used. In this way, all texts in the templates that use Smarty syntax {l s='text for translation'} can be changed.