cgoit / contao-form-fill-pdf-bundle
Fill PDF forms based on forms in contao
Installs: 55
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:contao-bundle
Requires
- php: ^8.1 || ^8.2 || ^8.3
- codefog/contao-haste: ^5.1
- contao/core-bundle: ^5.3
- doctrine/dbal: ^3.3
- mikehaertl/php-pdftk: ^0.13.0
- mvo/contao-group-widget: ^1.5
- symfony/config: ^6.1
- symfony/dependency-injection: ^6.1
- symfony/filesystem: ^6.1
- symfony/http-kernel: ^6.1
Requires (Dev)
- contao/manager-plugin: ^2.3.1
- phpunit/phpunit: ^10.3
- terminal42/contao-build-tools: dev-main
Suggests
- terminal42/contao-leads: Storing
- terminal42/notification_center: Sending
Conflicts
- contao/manager-plugin: <2.0 || >=3.0
README
With this bundle you are able to fill PDF forms with the submitted data of any contao form.
Setup
Setup is currently only possible by composer or the contao manager. Just require or search for cgoit/contao-form-fill-pdf-bundle
and install it.
Requirements
IMPORTANT: The bundle requires pdftk
binary to be present on the server. If the pdftk
binary is not present or usable on your server you can't fill your PDF templates with this bundle.
It might be possible that you can provide the appropriate binary for your architecture and set your LD_LIBRARY_PATH
accordingly but this is not tested and I can't give you any guarantee that this will work.
How does this bundle work?
To be honest: this bundle doesn't do much on it's own. Most of the hard work of merging your data with the PDF template is done by the outstanding library php-pdftk
. This bundle only prepares all the data which is then provided to this library together with the selected PDF template. Thus all the limitations (e.g. UTF-8 support, etc.) of the php-pdftk
library are also limitations of this bundle.
How to use?
Prepare your PDF template
First of all you need a PDF template in which you will merge your form data. You can create your template with every tool which is able to create PDF forms. Inside of this template give your form fields names with SimpleTokens. Doing so, the data will be merged into this fields afterwards.
You can use the following SimpleTokens:
##form_*##
:*
is the name of your form field in the contao form##formconfig_*##
:*
is a property of your contao form, e.g.id
##admin_email##
: the email of the administrator##filenames##
: a list of submitted filenames
Special cases
Currently I know three special cases where we have to talk about.
- Radio buttons: If you have a radio button menu in your HTML form you'll have to take care that the
on
-value in your PDF form matches the corresponding values in your HTML radio button. E.g. if your radio button is namedtest
with the values1
,A
andall
you'll have to add three radio buttons to your PDF form as well. All of them are named##form_test##
. Theon
values for the radiobuttons are1
,A
andall
. - Checkboxes: When you have checkboxes in your form the user normally is able to check multiple of them in the frontend. Every checkbox will have a different value. In your PDF template you'll have to append this value prefixed with an underscore to the fieldname. E.g. if your checkbox in your HTML form is named
test
with the values1
,A
andall
your fieldnames in your PDF template will be##form_test_1##
,##form_test_A##
and##form_test_all##
. Theon
value of the checkboxes in the PDF form is always1
for those fields. - File upload: Currently it's not possible to include the file itself in the merged PDF. If you add a file to your PDF only the path (as string) will be merged.
Prepare your form
In the configuration of your form you can enable the merging of data into your PDF templates via checking Merge PDF template
You then have to configure at least one PDF template which should be merged.
Compatibility with other extensions
As described above this extension works perfectly well with terminal42/notification_center
and terminal42/contao-leads
. There is also a solution if you want to combine this extension with terminal42/contao-mp_forms
.
Use with terminal42/contao-mp_forms
If you have the use case to collect some data in a multi step form created with terminal42/contao-mp_forms
and want to show the merged PDF e.g. on the summary step before you finally submit the form you can add a new FormField Generate PDF
in your form configuration. If this FormField is present it will merge the data which is collected until this step into the selected PDFs. Doing so you can refer to the merged PDF via the well-known Simple Tokens described above.
How to test
To make things easy a sample pdf template and a sample form is included in this bundle.
During installation/migration the sample PDF form as well as a sql script is copied to files/form-fill-pdf
. You can import the contao-form-fill-pdf-demo-form.sql
into your database. This will create a form in contao with every possible form field type (textfields, check box menus, password fields, ...). The also copied sample-form.pdf
can be used to merge the data from this contao form.