Newest Feature of Subscription

Learn more

Field Type Signature

Learn more

Field Type Location

Learn more

Field Type Calculation

Learn more

Multi Page Forms

Create PDF Documents with Visforms

This feature is part of the Visforms Subscription and not available in the free Visforms version.. It was added to the Visforms Subscription 3.4.0 which is currently released as a Beta version

Creating PDF Documents with Visforms is a newly developed, very powerful feature, which is just at it's beginning. At the moment the feature is released as a beta version and we strongly recommend not to use it on a productive system, at least only after very careful testing.

You can use this feature in order:

  • to allow the users of your website to download pdf files of there submissions in the frontend
  • to directly create (download), as an administration, extremely flexible PDF documents in the administration

This is a very brief introduction which you should read from start to end carfully in order to understand how this works.

Basically a PDF template is a html-tagged text, that contains placeholder, which are replaced with current set(s) of data stored with this form. Which data are use can be selected in different ways, depending on where you are creating the PDF Document (Frontend or Administration). After that a PDF document is created from the text, using the TCPDF library.

In the Visforms administration you can create and test PDF templates, which can then be used to allow the users of your website to download PDF files of there submissions in the frontend. Visforms provides powerful and flexible placeholder replacement tools for that purpose.

You can also use the Visforms administration to directly create (download), as an administration, extremely flexible PDF documents. In this case there are additional good tools which allow you to select the record sets that are used with the PDF template.

The basic structure on how you create a pdf template is very similar to how Visforms works overall

Each template is attached to a specific form, so a PDF templates view can only be reached when you are in a form context or from the forms view in the administration itself.

Some options and some tabs (like "Basic" and "Settings") in the PDF template configuration are self explanatory and are not discussed here.

Some thing you should know about TCPDF

Visforms uses the TCPDF library to create PDF documents and it supports any feature, which TCPDF supports. (You can check out the TCPDF Documentation if you want to learn more). These feature reflect in the tab "Settings".

Although TCPDF converts HTML into PDF you must know, that it does not support many feature, which a browser would support. So although you can achieve almost everything what you can achieve with a browser, with TCPDF as well, it must often be done in a different way.

Whereas with a browser you use CSS, with TCPDF you may have to use other means.

No Goes - Never use width attributes with tables

It is imperativ to know, what you can do in your PDF template-HTML and what are real no-goes!

One of the most important things to know is, that tables, and td's must never have a width attribute and that you must use the colspan attribute in order to set the width of a column. Because the text of the PDF template is entered in an editor field (tinymce) and because the first thing any editor does when you start dragging on a table border, is to set a table width, we have disabled this feature (dragging on table borders) in the editor (in the PDF template configuration).

Take a good look at our demos and template templates

Because we are aware, that it is a problem for you to figure, how the HTML of your PDF template has to look, we have created a set of template templates and some demo forms that include ready PDF templates. We strongly recommend to install the PDF demo forms (Visforms Dashboard) and to take your time in order to study the demo form PDF templates and our template templates. (If you want to get your hands dirty and start testing on the demo forms it is probably a good idea to copy the PDF template first and test on the copy :))

We appologize that the texts in our demo forms are a wild mix of German and English and Lorem Ipsum texts. Please don't mind the texts. Their only purpose is, to have content, which shows how you can achieve a specific layout (i.e. structure data in two or three columns, a longer floating text, position a logo and so on). It is the structure of the HTML of the demo forms which matters and can show you a lot and it is the SQL statements and there use, which you should study. We further appologize, that some of the fields in the demo form might seem a bit strange. Our purpose was to have forms with demo data available (which we created quick and dirty) and not to create fancy forms (which is of course very well possible with Visforms :))

PDF Template Parts

Basically each PDF template can consist of a header template, a document template and a footer template. We provide separate template templates for each part and in addition a couple of template groups, which comprize all three parts. On the tab "document" you can select either a document template (left side) or a complete template (right side) to start with. Header and Footer templates are created (inserted) at the respective tabs. If you have inserted a complete template on the document tab, this will insert a header and a footer template by automatic action. Each part can be modified or replaced separately.

The Placeholders - heart of your PDF template

The first thing you will notice, when you look on our example on the document tab is the placeholders inside the PDF template document. Basically all placeholders are of the format ${placeholdername} where the placeholdername may look differently.

Visforms Placeholder

First of all there are the Visforms placeholder, which are placeholder that come directly from the form to which the PDF template is attached and the fields of that form. Those placeholders can be inserted using the Editor Button "Visforms Placeholder". They are the same placeholders which you can already use in the form's e-mails and in the forms result message. In addtion to those Visforms placeholders there are other types of placeholders which you can use in various ways and at different points.

Placeholder for the Joomla! user and input framework objects

Format: ${user:UserProperty}, ${input:InputProperty}, i.e. ${user:id} or ${user:name}

Placeholder for the currently processed record set

${item:itemProperty} i.e. ${item:created} (mostly used in SQL-Statements as described below).

Placeholder for PDF document properties

[PNR] = Current Page Number, [NPS] = Total Page Count, [POP] = Current Page Number / Total Page Count

Placeholder for the current date

${currentdate}

Record Set Selection/Data Selection

With the record set selection you decide, which record sets submitted for the form to which the PDF template is attached, are used, in order to replace the placeholders in your PDF template texts, if you create the PDF document in the administration. This is your primary recordset selection. Mostly the record set selection is done directly on the Preview tab, where you have a lot of options like "Select Status", Select a specific record set id or all record sets (set the value for Reordset Id to 0), set a range limit (how many record sets are used starting with which record set) and so on. Any change of these options is stored by automatic action via AJAX and instantly used.

Further on it is possible to create custom SQL statements for the recordset selection. This is done on the tab "Data Selection". Here you can create custom SQL WHERE statements in order to customize the record set selection from the database (Please note, that you must not include the keyword where in the statement, just the conditions). It is possible to use placeholders in these SQL statements (See below: "Placeholder in SQL-Statements") which makes it an even more flexible feature. You can create up to 10 data selection SQL statements for each PDF template. If you have created a custom data selection SQL statement, (and saved the PDF Template), you can then select it on the Preview tab's option "Data Selection SQL".

If you create PDF documents in the administration there is an hierachie by which the data selection process is performed. If you have selected a specific recordset id on the preview tab, this record set will be used. If you set the recordset id to 0, and a Data Selection SQL Statement is selected, this statement will be used. The settings which you have made in the other options (Published, Preview Data Limitation Range and Preview Data Sort Order) will then be applied to the set of records which where selected so far. (If you set the recordset id to 0 and have no data selection sql statement selected, all record sets are selected according to the setting in the other options (Published, Preview Data Limitation Range and Preview Data Sort Order).

Looping through record sets

As a default, the whole template is repeated for each recordset of your data selection. Nevertheless, sometimes this is not want you want to achive. Instead you want create a list with the data of all recordsets within one document, i.e. for each recordset add a row to a table or a list item to a list. It is easy to create a PDF template that loops through all submissions and for example adds a row for each submission to a table (Check out the Bestellungen Template for the demo form Obst). Just add a class="loop" to the HTML-Element that should be multiplied for each submission (switch the editor view to the HTML source code (Toggle Editor) in order to do that). Please note, that it is not possible to use nested loop-Elements. So a HTML-class-loop element must not have a HTML-class-loop element child.

SQL Statements - Advanced Features

The purpose of the SQL-Statements created on the SQL-Statements tab is, to provide you a very powerful means to include additional data from the same form, from other Visforms forms or from any other place in the database into your PDFs. If you want to include data from the same form, just use the "Processtype" Form and add an SQL WHERE Statement (without the keyword where). Otherwise use the "Processtype" Free and add an SQL SELECT Statement. Those SQL statements are processed for each record set of your primary data selection so that you can add 1:n record sets with additional information to each record set of your primary data selection. Those SQL-Statements are processed both times, if you create PDFs in the administration and if you create PDFs from the frontend data views.

In order to be processed, those SQL-Statements must be inserted into the template Document. This is done by adding both, a class="sql" attribute and an id="SQL Statement id" attribute to a HTML element (i.e. a tr-Element). This HTML element must contain text with the proper placeholders (referencing the syntax of the data loaded by the SQL-Statement, as described below in "Placeholders from SQL-Statements"). If you have an 1:n relation between the primary recordset selection and the recordset selection of the SQL statement, the HTML element will by multiplied for each record set.

You have to switch to the HTML source code view (Toggle Editor) in order to enter the class and the id attribute easily. (Check out the invoice demo PDF template of the register demo form; the SQL statements on the "SQL Statements" tab, the HTML source code on the "Document" tab and the "Preview").

You must inculde a SQL-Statement with the proper class and id attribute only once. During the process of replacing placeholders, the replace values for the SQL-statement placeholders are "stored" and reused again. Please note, that it is the value of the last record which is stored as placeholder value in this case. So it is mostly the data from those sql statements which return one recordset with aggregated data, which you will reuse in your template.

You can use these feature to create aggregated information like sums, counts etc. and place this information anywhere in your template. You can use it to combine data submitted with one form with data submitted with another form, for example if you have one form where you collect a lot of user information and another form, where this user regularly puts orders with your business, then you could create a PDF template that merges the data of a specific user from the user information form with their multiple submissions of the order form. (Check out the invoice demo pdf template of the register demo form; the sql statements on the "SQL Statements" tab, the HTML source code on the "Document" tab and the "Preview").

Please Note: It is not possible to use nested SQL-Statement. So a HTML-class-sql element must not have a HTML-class-sql element child.

Placeholder from sql-Statements

Format : ${SQL-Statement id:SQL-Select field id}

Example: You have created an SQL-Statement on the SQL Statements tab, which you have given the id "sum". This SQL statement is: select round(sum(F2179 * F2180), 2) as sum, round(sum(F2179 * F2180) * 0.19, 2) as tax from vf38_visforms_143 where id < 10; If you want to use the result of this SQL-Statement the proper placeholders would be ${sum:sum} and ${sum:tax}

Placeholder in SQL-Statements

SQL-Statements can contain placeholder, which are replaced with the proper value, before the SQL-Statement is applied. This can either be placeholder for framework objects like the current user , i.e. ${user:id}, or placeholder which reference data from the parent item (the Visforms data recordset form your primary data selection, which is currently processed), i.e. ${item:created_by}. In the Data Selection SQL-Statements you can also use the Visforms placeholder instead of the database field names. i.e. ${maiden} like '%value 1%' instead of F111 like '%value 1%'

PDF Download in the frontend

According to the user permissions, Visforms will display PDF download links in the frontend data views. You can enable this feature in the form configuration "Dataview in frontend". This includes two options. The "Display PDF Download Button" option, where you can select on which type of view the button should be displayed (List View, Detail View, Both). After that you have to select a PDF template. If you select a "Single Record PDF Template" a PDF download button is displayed for each records set which the user is allowed to create a PDF from. If you select a "List PDF Template" and the user has permission to create a PDF at least of some of the displayed record sets, then a download PDF button is displayed at the top of the list view page, with which a PDF of all record sets, the user has permission for, can be created.

Temporaire PDF Download link for submitted data in the result message

In the form configuration on the tab "Result" you can add a temporaire PDF download link to the result message and select a PDF template for this purpose. Using the selected PDF template the user inputs just submitted with the form can be downloaded as PDF. These feature does not require to store the submitted user inputs in the data base. After the user has left or refreshed the page with the result message the link is no longer valid.

Screenshots

PDF Settings

Pdf settings

PDF Document Body with Placeholder

Pdf document

PDF Preview with recordset selection

PDF Preview

PDF Data Selection Sql Statements

Data selection

PDF Sql Statements

PDF sql statements

Back to list Find subscription