The Workflow-FormsToPDF module
I) Introduction
The Workflow-FormsToPDF module is used for exporting responses to the Forms plugin questionnaire in a template (or model) created by the user. Responses can be exported individually in the response viewing tab.
II) Use
1. Creating an export with the formstopdf workflow
You have created a form with at least one question and you have verified that your user has the necessary rights to use workflows.
a. Create a new workflow
In the menu select: system > workflow management
Click on create a workflow.
b. Create one or two steps
If only one step is created, it will be possible to export the same response several times. If two are created, a response will be exportable only once.
c. Create an action associated with your step
Click on "Add an action".
In the modify action page, select the task "Export a form to a pdf edition", click on the "plus" icon to add.
Click on modify the workflow.
d. Create a new Template
In modify the workflow then in modify the task, click on "Manage templates".
Click on "Add a template".
Give a name to the new template and associate the template with a form then save.
Click to modify the newly created template. The questions and other elements associated with the form (Bookmark) are now displayed in the section to the right of the page. Click on one of the Bookmarks to copy it and paste it into the template being created. The Bookmark will be replaced by the corresponding data when generating the PDF.
Save the template.
e. Associate the new template with the form
Save the template with the associated form:
f. Activate the workflow
In the menu select: system > workflow management Activate the workflow.
g. Associate the Workflow with the form
On the form modification page, associate the workflow with the form
h. Export a response in PDF format
It is now possible to export the form responses according to the Template that was created. Go to the response viewing page and click on a response.
Click on the action that was named earlier.
i. Download the PDF
In System > My file requests Click on download
III) Customize the display of question types (entrytype)
The Form plugin offers different types of questions: date, text, image, file etc. To adapt the display of responses according to their type (Entrytype), the module-workflow-formstopdf uses Freemarker macros (wiki macro links). In the source code of the module, there is a macro whose role is to call the macro that corresponds to the Entrytype of the question. This macro is located here: lutece-wf-module-workflow-formstopdf/webapp/WEB-INF/templates/admin/plugins/workflow/modules/formspdf/display_entries/displayEntry.ftl
<#macro displayEntry q> <#if q??> <#assign entry=q.question.entry > <#assign list_responses=q.getEntryResponse() > <#if entry.entryType.beanName == "forms.entryTypeArray"> <@displayEntryTypeArray entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeAutomaticFileReading"> <@displayEntryTypeAutoFileReading entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeCamera"> <@displayEntryTypeCamera entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeCartography"> <@displayEntryTypeCartography entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeCheckbox"> <@displayEntryTypeCheckbox entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeComment"> <@displayEntryTypeComment entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeDate"> <@displayEntryTypeDate entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeFile"> <@displayEntryTypeFile entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeGalleryImage"> <@displayEntryTypeGalleryImage entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeGeolocation"> <@displayEntryTypeGeolocation entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeImage"> <@displayEntryTypeImage entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeMyLuteceUser"> <@displayEntryTypeMyLuteceUser entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeNumber"> <@displayEntryTypeNumber entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeNumbering"> <@displayEntryTypeNumbering entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeRadioButton"> <@displayEntryTypeRadioButton entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeSelect"> <#elseif entry.entryType.beanName == "forms.entryTypeSelect"> <@displayEntryTypeSelect entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeSelectOrder"> <@displayEntryTypeSelectOrder entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeTelephoneNumber"> <@displayEntryTypeTelephoneNumber entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeTermsOfService"> <@displayEntryTypeTermsOfService entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeText"> <@displayEntryTypeText entry=entry list_responses=list_responses /> <#elseif entry.entryType.beanName == "forms.entryTypeTextArea"> <@displayEntryTypeTextArea entry=entry list_responses=list_responses /> <#else> <@displayEntryTypeText entry=entry list_responses=list_responses /> </#if> </#if> </#macro>
This redirection macro takes a parameter q which corresponds to the value of the response contained in position_X To call it according to the chosen syntax:
<#@displayEntry q=position_7/>
or
[#@displayEntry q=position_7/]
The Bookmark of a question is actually a call to the redirection macro.
Configuration of Freemarker Macros Syntax
Freemarker tags are usually defined in a way similar to that of html with < and >. For example, to define a macro: <#macro maMacro arg1/>. And to call it: <@maMacro arg1= arg1/>.
This syntax is incompatible with the use of the RichTextEditor which reformats elements to prevent display bugs and XSS attacks. For example: <@maMacro arg1= arg1/> becomes <p><@maMacro arg1= arg1/></p>. To use the response Bookmarks (which are actually calls to macros) with the RTE, you need to modify the Freemarker syntax.
Adding [#ftl] at the very beginning of the template makes it possible to use Freemarker macros with a different syntax that is compatible with the RichTextEditor. To define a macro: [#macro macro maMacro arg1 /]. To call a macro: [@maMacro arg1= arg1/]. The module automatically adds and removes the [#ftl] header when modifying the option below.
Without the RTE, it is possible to configure the display of a macro, because the RTE reformats the HTML. It is also easier to customize a macro without RTE with the <> syntax, because you can then copy and paste the existing display macros that you want to modify.
Example of customization
At the template editing stage, we have to select the without Rich Text editor option. You need to retrieve the macro of the Entrytype that you want to modify in the source code of the module-workflow-formstopdf. Here, we identify the macro: DisplayEntryTypeText. We copy/paste the content of the macro into the template form.
You can now modify the macro to have the desired display.
In this example, the color and style are customized.
As a result, we have the response whose style has been customized.