Please rate how useful you found this document: 
Average: 3.3 (6 votes)
Contents: [hide]

Overview

Output Documents are files generated while running a case, which are meant to be printed out or stored digitally outside ProcessMaker. Output Documents are useful for creating external records of case data, as well as creating formatted documents such as letters, bills and receipts. Output Documents are generated from HTML templates and can contain variables, which are auto-inserted when the Output Document is generated as a step when running a case. Output Documents are generated as PDF (Portable Document Format) and/or DOC (Word document) files, so they can be easily opened and printed using Adobe Acrobat and Microsoft Office (or alternatives such as Foxit Reader, Evince, Okular, WordPerfect, AbiWord and OpenOffice).

If the Output Document is generated as a PDF file, either the HTML2PDF (an old version of a PDF generator which is no longer recommended) or the TCPDF library can be used to generate the PDF file.

HTML2PDF can be used to insert some of the formatting options listed below, such as page breaks and headers and footers. The advantage of this library is that generates compressed PDF documents by omitting extra parameters in the code, which means that the PDF file will be smaller in size.

TCPDF is compatible with more recent versions of PHP and is recommended if the document that will be generated contains images or it is necesary to minimize the size of the file.

Note: The Output Document feature is not available for ProcessMaker Mobile as a step: it will not open the case or create a case if the Output Document is the first on the display list. If a process has a Dynaform and then the Output Document step, the Mobile version skips that part and continues. This feature will be implemented in future versions.

Output Document Management

To see the list of output documents created in the process, click on the Output Documents option inside the Process Objects toolbox:

All the Output Documents will be listed:

Where:

  1. Search Field: Enter the title of an output document in this field. As the text is entered all coincidences will be filtered in the list below.

  2. Create: Opens a window to create a new output document. It is possible to use either this option to create an output document or this option.

  3. Show ID: Obtains the unique identification code of the output document. For instance, use this ID to create an output document using the PMFGenerateOutputDocument function.

  4. Title: Shows the title of the output document created in the project. The list is sorted in ascending order by default, but it is possible to view the list of documents in descending order by clicking on the down triangle next to "Title".

  5. Type: Shows the type of document, which always is HTML.

  6. Edit: Opens a window to edit the corresponding output document.

  7. Open Editor: Opens the WYSIWYG HTML editor to edit the document template:

    Read this documentation to learn how to use the HTML editor.

  8. Delete: Click this option to delete the output document. The following confirmation message will be shown:

    Select Yes to delete the output document and the flash message "Output document deleted successfully" will be shown in the upper part of the designer.

  9. Pagination Control: When there are more than 10 documents created in the process, a new page is added to this window. To navigate through these pages use the > or < options. To view a specific page, click on the number of the page in the control.

Creating Output Documents

To create a new Output Document, open a project and go to the right side of the screen where the Process Objects toolbox is located. Hover the pointer of the mouse over the + icon and the Create option will be displayed to the left:

Click on the Create option and the following window will be displayed:

Where:

  • Title: Adds a title that identifies the output document.
  • Filename generated: The filename to be generated when an output document is created when running cases. Note that paths cannot be included in the filename, since output documents are stored in a standard location in the file system. To include a system or case variable in the filename, click on the [@@] button and select a variable.

    Note: It is recommended to only use @#variable in filenames and not @@variable because the Windows operating system can't handle filenames that contain " (double quotation marks).

  • Description: A small description about the document, which should inform the user about the general content or purpose of the document.
  • Report Generator: Choose the engine that will generate the output documents. Use HTML2PDF with ProcessMaker versions earlier than 2.5, otherwise use TCPDF with versions 2.5 or above.
  • Media: Select the paper size:
    Paper Type Width (mm) Height (mm)
    Letter 216 279
    Legal 216 357
    Executive 184 267
    B5 182 257
    Folio 216 330
    A0Oversize 882 1247
    A0 841 1189
    A1 594 841
    A2 420 594
    A3 297 420
    A4 210 297
    A5 148 210
    A6 105 148
    A7 74 105
    A8 52 74
    A9 37 52
    A10 26 37
    Screenshot640 640 480
    Screenshot800 800 600
    Screenshot1024 1024 768
  • Left: Size of the paper's left margin in mm.
  • Right: Size of the paper's right margin in mm.
  • Top: Size of the paper's top margin in mm.
  • Bottom: Size of the paper's bottom margin in mm.
  • Output Document to Generate: Select whether the output document will be generated in DOC, PDF, or BOTH formats.
  • PDF Security: An option that allows passwords to be set for the generated PDF document and restricts how it may be used. Select one of the following options:
    • Disabled: Default. No security will be applied to the generated PDF document.
    • Enabled: If selected, the following security options are displayed:
      • Open Password: Define a password to open the PDF document.
      • Owner Password: Define a password to change the PDF document's permissions.
      • Allowed Permissions: Select how the PDF document may be used. To select more than one option, hold down on the CTRL key while clicking the following options:
        • Print: The document can be printed.
        • Modify: The document can be edited.
        • Copy: The document can be copied.
        • Forms: The fields in the document may be filled in.
  • Enable Versioning: Presents a dropdown with two options, which are "Yes" and "No". If "Yes" is chosen, then ProcessMaker will keep multiple versions of the output document. Versioning is useful if the same output document is created at multiple steps in a case. This option allows a record to be kept of how the document's data changes over the course of a case, which is useful for maintaining audit trails.
  • Destination Path: Enter the name of the folder where the output document should be stored. Click on the [@@] button to select a variable to use in the folder name. To specify a subfolder inside other folders, enter a path to that folder, separating each folder with a / (forward slash). For example: Invoices/@#USR_USERNAME/@#subject_@#date
    To see a list of input documents, output documents and attached files found in each folder, go to HOME > Documents and click on the folder.
    Note: The Destination Path is a virtual path and it does not effect where output documents are stored in the file system. All case files will be stored inside the path where ProcessMaker has been installed.
  • Tags: Enter the name of the identifying tag(s) that will be associated with this output document. To specify more than one tag name, separate each tag name with commas. Click on the [@@] button to select a variable to use in the tag name. Tags are really useful when looking for output documents in the ProcessMaker database.
  • By clicking on the generated file link: Select whether the file will be downloaded or opened in the browser window.
    • Download the file: Download the file directly to the local computer. By choosing this option, the browser will automatically download the file. This is the recommended option when creating output documents.
    • Open the file: Open the file in the browser window.

      Note: If selecting this option when configuring an output document, take into consideration that the browser must be configured differently to open the files downloaded. To be able to open .pdf files, install Adobe Acrobat Reader. It is recommended to use the Download the file option to avoid the extra configuration that opening the file in the browser window requires.

Creating Output Documents Using TCPDF Generator

Usually when PDF Documents had more than 6 pages and were generated with the HTML2PDF library, they can't be created and downloaded producing an error in the HTML code. To improve the generation of PDF documents, the TCPDF generator was included inside ProcessMaker to allow users the creation and generation of PDF and DOC documents without having issues with the amount of pages created.

This generator supports UTF-8 Unicode and right-to-left languages. It also has backward compatibility with documents created in previous versions of ProcessMaker. This is a great enhancement, especially if documents with images in them need to be generated.

When an output document is being created, the new generator can be chosen using the option seen in the image below:

Creating Output Documents Using HTML2PDF Generator

The HTML2PDF generator can be used to generate documents with less than 6 pages. The HTML2PDF generates compressed documents without configuring extra parameters into the code, which means that the PDF document generated will be smaller in size.

The HTML2PDF library allows users to:

To avoid errors using the HTML2PDF library, consider the following:

  • Avoid the creation of spaces with the TAB key.

Editing Templates

To edit the template of an output document, go to the Main Toolbox and click on Output Documents. A list of all the templates created for the process will appear there. Select the output document that needs to have its content edited and click on the Open Editor button. A new window will open where the document can be changed and corrected in any way that the user wants. There is also a small HTML button that the user can click to access the HTML code and format the document. Once the document is formatted, click on the Save button and a quick message will appear telling the user that all changes made were saved.

Enter the desired text into the Output Document template. Entering a hard return generates a new paragraph in the HTML, which inserts an extra blank line in the text. To enter a line break that doesn't insert a blank line in the text, press SHIFT + ENTER. The editor supports the standard key combinations of CTRL + C to copy, CTRL + X to cut, and CTRL + V to paste. Changes can be undone by pressing CTRL + Z. Multiple levels of undo are supported. After undoing changes with CTRL + Z, press CTRL + Y to redo the changes. When done editing the Output Document template, click Save to store the changes and then click on the close icon to close the editing window.

Inserting Variables

Case variables and system variables can be inserted into the text of an output document:

  • @#VARIABLE-NAME inserts the value of the variable without any changes.
  • @@VARIABLE-NAME inserts the value of the variable enclosed in "" (double quotation marks). Any quotation marks inside the value can be escaped with backslashes, such as "Don\'t say \"hello\"".

If a variable is associated with a dropdown box, checkbox, checkgroup, radio group, suggest box, datetime or file control in a Dynaform, then there will be an additional variable named @#VARIABLE-NAME_label, which is created when the Dynaform is submitted. This variable holds the label of the selected option, which is displayed to the user, whereas @#VARIABLE-NAME holds the key of the selected option. For example, a variable named "selectService" that is associated with a dropdown box might have a value of "accounting" in its @#selectService variable, but "Accounting and Tax Filing Service" in its @#selectService_label variable. For more information, see Inserting Variables.

Variables can be inserted in the Output Documents editing window.

Now for the variables, next to the Bold property there is a variable picker. Click on it to choose variables to relate to the empty fields created. Select the variables with @# signs to add variables to the document with no changes. For example, Name will have the @#USR_USERNAME variable. Continue to add variables to the other fields, and then click on Save to store all changes made in the document.

Line Breaks in Textareas

A textarea control allows more than one line of text to be input into a field. The information in this control is stored in one single line with \n as the representation for each line break, therefore, whenever using the Textarea's variable, the information will be displayed all together on the same line.

To preserve line breaks when showing the textarea information in messages, emails, etc. it is recommended to use the nl2br PHP function within a trigger.

For example, create the following trigger and place it after the Dynaform.

@@textareaVar = nl2br(@@textareaVar);

Remember that to insert the value of a variable without any changes, the prefix @# must be used before the name of the variable. In this case the textarea variable will be @#textareaVar, as explained in the Inserting Variables section.

The function will insert HTML line breaks before all new lines. Therefore, the e-mail will display the variable's information preserving the line breaks typed in the textarea.

Formatting Output Documents

ProcessMaker includes a new advanced editor for documents as seen in the image below:

This toolbar provides several options to clean up the document. To add formatting to output documents, the toolbar includes the following buttons:

  • Upload File: Click on this button to upload a file with an .html or .htm extension.

  • Variable Picker: Choose the type and prefix of the variable to be called in the document.

  • Bold: Bold the selected text (a heavier weight). Shortcut: ctl + b
  • Italics: Italicize the selected text (inclined text). Shortcut: ctl + i
  • Underline: Underline the selected text. Shortcut: ctl + u
  • Left align: Align the selected text along the left-hand border.
  • Center: Align the selected text in the center.
  • Right align: Align the selected text along the right-hand border.
  • Text Align: Justify the entire selected text.
  • Font: Allows the user to choose one of many different fonts to customize the document.
  • Font Size: Increases or decreases the font size of the selected text.
  • Cut, Copy and Paste: Cut will remove the selected text from its position, while Copy creates a duplicate. Paste copies text and inserts it into the document.
  • Ordered List: Insert an ordered list, which begins counting from 1.
  • Un-ordered List: Insert an unordered list, which uses bullet points instead of numbers.
  • Outdent, Indent, Quote: Outdent and Indent will add a space to a selected text; outdent will move the text toward the left marging and indent will move the text away from the left marging. Quote works by selecting a text and aligning the text inside of quotation marks.
  • Table Configuration: Creates and edits a table of as many rows and columns as needed, can also insert more rows and columns or delete them. The columns in the table can be ordered, split or merged as needed.
  • Undo and Redo: Recover or revoke previous actions made in the document.
  • Link and Image Configuration: These tools insert and edit links, as well as convert links to normal text. An image can also be inserted or edited.

    Note: Take into account that the source of the images inserted must be from a URL with an http or https protocol. It is not possible to upload an image from a local source using this editor. To upload an image from a local resource, first upload it as a Public File and access it using this information.

  • Font Color: Change the color of the selected text.
  • Text Highlight Color: Change the highlight (background) color behind the selected text.
  • Edit CSS Style: Contains more options to make more detailed edits to the text.
  • Lines: Adds lines to mark different sections of the document
  • Clear Formatting: Removes any formatting from the selected text.
  • Grid Visual Help: Enables or disables the visual help grid in a selected table.
  • Subscript and Superscript: Highlight a letter, number, symbol, or figure to place it above the rest of the text (superscript) or below (subscript).
  • Direction: Changes the direction of the text to left to right or right to left.
  • HTML: Edit the HTML code of the template.

Avoid inserting HTML formatting tags inside a variable name, because it make the variable unable to be recognized by ProcessMaker. For example, if bold tags are inserted inside the variable @#USR_USERNAME, it becomes @#US<b>R_USER</b>NAME. Since ProcessMaker can't find find the variable @#US, it will print the variable name in the generated output document.

Editing the HTML Code

For more control over the formatting of a template and the use of more advanced types of HTML elements such as images or tables, the HTML code can be directly edited by clicking on the HTML button in the toolbar. When done editing the HTML code, click on the Update button to save it and see the result in the document.

Inserting Images

To insert an image into an output document, first upload the image file to the public directory in the ProcessMaker server with the Process File Manager (or another publicly accessible location). Take the ProcessMaker logo on the wiki page as an example. The URL would be the following "http://wiki.processmaker.com/sites/default/files/full-logo.png"

Now create an output document by hovering your cursor over the plus sign next to the Output Documents option in the Main Toolbox of the Process Map and clicking Create. The image below shows how the output document should be configured. Take into consideration that TCPDF needs to be selected in the Report Generator field to be able to see images. Click on the Save button to create the output document and add it to the Output Documents window.

Once in the Output Documents window, click on the Open Editor button to open a Word-like editor.

Then click on the HTML button to open the HTML Source Editor window.

Now add the following code to insert an image:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<p>This is a test for images</p>
<p><img src="http://wiki.processmaker.com/sites/default/files/full-logo.png" /></p>
</body>
</html>

Notice that the "src" or source of the image is the URL of the logo. After adding the code, click on the Update button to check if the image was properly uploaded. If the image is seen in the Edit Output Document window then it will be seen when running a case.

If there is an error then the following broken image will be shown in the editor. Check the code or image for any errors to be able to see it when running a case.

Inserting Form Fields

To insert form fields inside of an output document, edit the HTML code and create an HTML <form>. In that <form>, add <input>, <select>, and/or <submit> fields.

For example, this template code includes the <form>, <input> and <select> tags:

<form name="MyFormName">
First Name: <input type="text" name="firstName" size="20" value="Jo Anne"><br>
Last Name: <input type="text" name="lastName" size="20" value="Summers"><br>
<input type="checkbox" name="contactClient" value="contact" checked>Contact Client<br>
<select name="howContact">
    <option value="telephone">Telephone</option>
    <option value="fax" selected>Fax</option>
    <option value="email">Email</option>
 </select><br>
</form>

When updated, the code will look like the image below, allowing the document to run with the user name and the name of the case started automatically filled in:

Note that these form fields are not interactive, so the content of the fields can not be edited.

Inserting Variables Inside Form Fields

System variables and case variables can be inserted inside form fields. For example, to insert the system variables @#USR_USERNAME and @#CaseStarted into fields named "username" and "timeStarted" respectively:

<form name="MyForm">
Current user:<br>
<input type="text" name="username" value="@#USR_USERNAME"><br>
When case started:<br>
<input type="text" name="timeStarted" value="@#CaseStarted"><br>
</form>

Warning: If inserting inside an <input> field, only reference variables as @#variable-name. Do NOT use @@variable-name, because it will insert a set of double quotation marks inside a set of double quotations marks, which will mess up the HTML tag.

For example, this bad template code:

<input type="text" name="username" value="@@USR_USERNAME">

will generate erroneous HTML code like:

<input type="text" name="username" value=""admin"">

Checkboxes in Output Documents

In an output document, a checkbox is marked if it has the checked property defined in its HTML code.

This checkbox is marked:

<form name="MyForm">
<input type="checkbox" name="contactClient" value="contact" checked>Contact Client<br>
</form>

This one is not marked because there is no checked property:

<form name="MyForm">
<input type="checkbox" name="contactClient" value="contact">Contact Client<br>
</form>

To use a case variable to mark a checkbox in an output document, place the case variable in the HTML code like this:

<form name="MyForm">
<input type="checkbox" name="contactClient" value="contact" @#markContactClient >Contact Client<br>
</form>

If the value of @#markContactClient is "checked" then the checkbox will be marked. If it is "" (empty string), then it won't be marked in the output document.

Create a trigger that will set the value of @@markContactClient to "checked" or "", depending upon the value of a checkbox in a Dynaform. Set this trigger to fire before the step that generates the output document.

For example, if the variable associated with the checkbox control in the Dynaform is "contactClient", then use this PHP code to check whether the checkbox is marked to set the value of @@markContactClient.

@@markContactClient = '';
if (isset(@=contactClient) and !empty(@=contactClient) and @=contactClient[0] == 1) {
   @@markContactClient = 'checked';
}

Note: Checkboxes have a value of array(1) if marked or array(0) if unmarked. Checkboxes inside grids are not placed inside arrays, so they have a value of 1 if marked or 0 if unmarked.

Inserting Page Breaks

To insert a page break in DOC files, edit the HTML code for the output document and define a style that causes a page break before an HTML element. Then apply that style to an HTML element, such as a line break or a paragraph.

For example, use the following code:

<style>
.pageBreak { page-break-before: always; }
</style>
<p>This is page 1.
<br class="pageBreak">
This is page 2.</p>

To insert a page break that will only appear in PDF files generated using the HTML2PDF library, edit the HTML code of the output document and add the HTML comment: <!--NewPage-->

For example, use the following code:

<p>This is page 1.</p>
<!--NewPage-->
<p>This is page 2.</p>

Page Headers and Footers (HTML2PDF Library)

Output Documents do not have a property to add page headers and footer, but these can be added manually if using the HTML2PDF library to generate PDF files. To define a page header in an Output Document, edit the HTML code and add text between <!--header starts--> and <!--header ends--> tags. Note that these are custom comment tags used by HTML2PDF and these codes will be ignored in the DOC files and PDF files created with TCPDF.

For example:

<!--header starts-->
<div style="position: fixed; top: -5mm; left: 0mm;">...your header content...</div>
<!--header ends-->

To avoid the header being placed on top of content inside the Output Document, set the header above the content with a style setting such as top: -5mm;. However, make sure that the top margin of the Output Document is set to 5mm or larger.

To insert a page footer, edit the HTML code of the Output Document and add text between <!--footer starts--> and <!--footer ends--> tags. For example:

<!--footer starts-->
<div style="position: fixed; bottom: 5mm; left: 0mm;">...your footer content...</div>
<!--footer ends-->

To avoid the footer being placed on top of content inside the Output Document, set the footer below the content with a style setting such as bottom: 5mm;. However, make sure that the bottom margin of the Output Document is set to 5mm or larger.

Note: The footer and header comments only work if using the HTML2PDF engine to generate the Output Document.

Page Numbers and File Information (HTML2PDF Library)

If generating PDF files using the HTML2PDF library, it is possible to insert page numbers and file information in the generated Output Document, using the following directives:

Directive Description
##PAGE## Number of the current page.
##PAGES## Total number of pages in the generated PDF file.
##FILENAME## The URL where the source HTML is located, such as:
http://example.com/files/98534779755ef0116e951f8051419251/outdocs/83393260655ef0978d76fd0041065478_2.html.
This location cannot be used externally. It either has to be converted into a URL such as:
http://example.com/sysworkflow/en/neoclassic/cases/cases_ShowOutputDocument?a=83393260655ef0978d76fd0041065478&v=4&ext=html
Or a file location of the server, such as:
/opt/processmaker/shared/sites/workflow/files/985/347/797/55ef0116e951f8051419251/outdocs/83393260655ef0978d76fd0041065478_4.html
##FILESIZE## The size of the HTML source file in bytes.
##TIMESTAMP## The time when the Output Document was generated in "YYYY-MM-DD HH:MM" format.

For example the following code prints out the page number and the total pages in the footer of each page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<p></p>
<!--footer starts-->
<div style="position: fixed; bottom: 5mm; width: 100%;">
    <center>Generated: ##TIMESTAMP##<br />Page ##PAGE## / ##PAGES##</center>
</div>
<!--footer ends-->
<p>This is the first page</p>
<!--NewPage-->
<p>This is the second page</p>
<!--NewPage-->
<p>This is the third page</p>
</body>

</html>

At the bottom of each page will appear, the footer text will appear:

Formatting Documents to Display Content in RTL

To display right-to-left languages correctly, such as Arabic and Hebrew, read the following instructions:

For content inside paragraphs, add dir="RTL" to the <p> tags:

<p dir="RTL">Testing RTL skin and language
  ...
</p>

For content inside tables, add dir="RTL" to the <table> tags:

<table dir="RTL">
  ...
</table>

For example, the following output document template displays a table in right-to-left format:

<p dir="RTL">Invoice Details</p>
<table class="mceItemTable" dir="RTL" border="0" align="right">
<tr>
<td>Reference</td>
<td>Number</td>
</tr>
<tr>
<td>Invoice approval</td>
<td>1</td>
</tr>
</table>

The resulting output document will be generated as a .doc document

Grids in Output Documents

The fields of a grid can be inserted into an output document by editing the HTML code of the output document. To do this, use an opening tag with the name of the variable that is related to the grid, @>GRID-VARIABLE, enclosed inside HTML comment tags <!-- ... --> to open the grid.

<!--@>GRID-VARIABLE-NAME-->

Then, insert the fields into the grid using their IDs prefixed by @#. Finally, close the grid by using a closing tag with the name of the variable that is assigned to the grid enclosed inside HTML comment tags. Like this:

<!--@>GRID-VARIABLE-NAME--> @#FIELD-1 @#FIELD-2 @#FIELD-3 <!--@<GRID-VARIABLE-NAME-->

The fields enclosed in the opening and closing grid tags will be repeated as many times as there are rows in the grid. Remember that grid names and field names are CASE SENSITIVE, so they must be spelled exactly as they were defined.

Example: Expense Report

To design a travel expenses report, the following output document should list each of the expenses in a grid associated to a variable named "Expense_Variable_Grid". This grid contains four fields that have the IDs "Date", "Type", "Description", and "Amount".

<p align="center"><b>Travel Expense Report - @#REPORT_MONTH_label</b></p>
<p align="center"><span>@#FIRST_NAME @#LAST_NAME</span></p>
<p align="left"></p>
<table border="1" cellspacing="0">
<tbody>
<tr><th>Date</th><th>Type</th><th>Description</th><th>Amount</th></tr>
<!--@>Expenses_Grid_Variable-->
<tr>
<td>@#Date_label</td>
<td>@#Type</td>
<td>@#Description</td>
<td>@#Amount</td>
</tr>
<!--@<Expenses_Grid_Variable--></tbody>
</table>

The code added in the HTML Source Editor window will look like the image below:

The HTML Editor will show a preview of the code inserted.

For example, for a case like the one shown in the image below:

The output document generated will look like the image below when opened in a .pdf format.

Note that the GRID-VARIABLE-NAME can also be generated by using the executeQuery() function to query a PM Table, Report Table or an external database. If the database has different field names than those in the output document, use "AS" to rename the fields. For example, a trigger containing the following code can be fired BEFORE the above Output Document is generated:

$db = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX'; //Unique ID for an external database
$query = 'SELECT EXP_DATE AS Date, EXP_TYPE AS Type, EXP_DESC AS Description, EXP_AMT AS Amount FROM EXPENSES';
@@EXPENSE_GRID = executeQuery($query, $db);

Likewise, the trigger can manually create EXPENSE_GRID as an associative array of associative arrays:

@=EXPENSE_GRID = array(
    '1' => array('Date'=>'2017-04-25', 'Type'=>'Airfare', 'Description'=>'Flight to Paris', 'Amount'=>1295.35),
    '2' => array('Date'=>'2017-04-26', 'Type'=>'Lodging', 'Description'=>'Sheraton Hotel',  'Amount'=>300.00 ),
    '3' => array('Date'=>'2017-04-27', 'Type'=>'Meals',   'Description'=>'Lunch w/ client', 'Amount'=>104.95 )
);

The example used in this section can be downloaded by clicking here.

Normally, a cell takes up the space it needs to display its content. To avoid conflicts with the amount of information displayed in a cell, it is recommended to specify the width of each table cell.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<p align="center"><b>Title Report</b></p>
<table width="100%" border="1">
<!--@>GRID-VARIABLE-NAME-->
<tr>
<td width="25%">@#Field-1</td>
<td width="25%">@#Field-2</td>
<td width="25%">@#Field-3</td>
<td width="25%">@#Field-4</td>
</tr>
<!--@<GRID-VARIABLE-NAME-->
</table>
</body>
</html>

For example, if the width property is applied to the table of the previous example, the preview of this table will look like:

The output document will look like:

Grids with a Fixed-Width Font

The default font for Output Documents is Arial, which is a variable-width font. It is hard to create neat columns of data with a variable-width font. Therefore, it is recommended to edit the HTML code and set the grid fields inside <pre>...</pre> tags or <tt>...</tt> tags, so the columns of data will line up in a fixed-width font.

For example:

    <center>
        Travel Expense Report <br> @#FIRST_NAME @#LAST_NAME <br> @#REPORT_MONTH <br>
    </center>
    <pre>
Date           Type of Expense     Description            Amount
<!--@>EXPENSE_GRID-->
@#DATE         @#TYPE              @#DESCRIPTION          @#AMOUNT
<!--@<EXPENSE_GRID-->
</pre>

Grids Inside an HTML Table

For even better formatting of grid data, edit the HTML code and set the the grid inside an HTML table.

Here is an example of the same grid fields inside an HTML table:

<center>
Travel Expense Report<br>
@#FIRST_NAME @#LAST_NAME<br>
@#REPORT_MONTH
</center>
<br>
<table><tbody>
<tr>
  <th>Date</th><th>Type Of expense</th><th>Description</th><th>Amount</th>
</tr>
<!--@>EXPENSE_GRID-->
<tr>
  <td>@#DATE</td><td>@#TYPE</td><td>@#DESCRIPTION</td><td>@#AMOUNT</td>
</tr>
<!--@<EXPENSE_GRID-->
</tbody></table>

The result in an output document would be:

Editing the HTML in the Database

The graphical editor in ProcessMaker strips away unrecognized HTML tags, which can cause changes to the formatting of output documents. The only way to get around this problem is to edit the HTML code of output document in the database. It can be edited by using PhpMyAdmin to enter the wf_WORKSPACE database in MySQL to search for the output document's template in the OUTPUT_DOCUMENT table. It can be found with the following query:

SELECT OUT_DOC_UID, OUT_DOC_TITLE, OUT_DOC_TEMPLATE FROM OUTPUT_DOCUMENT

If using PhpMyAdmin, click on the record's Edit link to edit the output document's template:

Errors with Output Documents

Error While Generating PDF Documents

PHP version 5.4.0 or less must be installed to use the HTML2PDF library to generate PDF documents. Otherwise, a blank page will be generated. If a later version of PHP is installed, use the TCPDF library to generate output documents.

Variables are not Inserted

If variables are not inserted into an output document, then either:

  1. The variable name was not spelled correctly. Remember that system and case variable names are case sensitive. Re-check the spelling by looking at the field name in the Dynaform or the variable name in the trigger where it was defined.
  2. The case variable doesn't exist when the output document was created. If an output document references fields from a Dynaform used later in the process, then the case variable doesn't yet exist. Also, remember that case variables for each field in a Dynaform are only created when the Dynaform is submitted. If the user clicks on the Next Step link in a Dynaform whose Next Step Link property is set to "No Save & Continue", then none of the data in the Dynaform will be saved.

To determine what the problem is, run a case with the Trigger Debugger turned on and check whether the variables exist and what values they contain.

Output Document is Empty

If an empty Output Document is generated, then there probably wasn't enough session memory to properly generate the document. Large output documents may need more than 80MB of session memory. Try increasing PHP's memory_limit setting.

Error in HTML2PDF

If an error message appears about a class in HTML2PDF saying "out of memory", then the pcre.backtrack_limit setting probably needs to be increased to allow bigger style definitions, larger template files and deeper levels of nested tables/divs. pcre.backtrack_limit is a new setting introduced in PHP 5.2.0.

Edit php.ini, which is the PHP configuration file on the server running ProcessMaker, and add/modify the following line to increase the backtrack_limit:

pcre.backtrack_limit=1000000

Then, restart Apache for the new setting to take effect.

Using Non US-ASCII Characters in Output Documents

To use characters inside an output document and generate documents in HTML2PDF (the old version), then follow the steps below to be able to open a document with Chinese, Arabic, Japanese and others characters successfully.

  1. Download this file (it will download automatically depending on your browsers configuration) to allow the use of characters inside an output document. The file that has been downloaded must be added into the following route in the ProcessMaker installation: [installation path]/gulliver/thirdparty/html2ps_pdf/fonts.

    As of ProcessMaker 3.2.2, the thirdparty folder is no longer part of the gulliver folder. Then, the file that has been downloaded must be added into the following route: [installation path]/thirdparty/html2ps_pdf/fonts.

    Remember to give the folder all the corresponding permissions.
  2. Create an output document with the specifications shown in the image below. Notice that "HTML2PDF" will be selected in the "Report Generator" field. Click on the Save button to store the document.

  3. Once saved, open the editor of the output document recently created by clicking on the Open Editor button.

  4. Add text with Chinese characters such as: "This is an example with Chinese characters 這是一個用漢字的例子".

  5. When a case runs, both .doc and .pdf options will be available. Click on the link to start the download of the documents.

  6. Notice that when the documents are opened the characters will be displayed correctly in both .doc and .pdf as seen in the images below.

  7. Other characters can also be added to output documents.

Output Documents in Multiple Languages

There are two ways to create an output document in multiple languages. The first way is to generate the output document's HTML content dynamically in a trigger based on the system language.

For example, the following trigger generates the HTML content dynamically in Spanish and English:

//content in Spanish:
if (@@SYS_LANG == 'es' or @@SYS_LANG == 'es-ES')
{ @@fileContent = "<p><b>Nombre del Cliente:</b> ".@@clientName."</p>\n". "<p><b>Dirección del Cliente:</b> ".@@clientAddress."</p>\n"; }
else
//content in English:
{ @@fileContent = "<p><b>Client Name:</b> ".@@clientName."</p>\n". "<p><b>Client Address:</b> ".@@clientAddress."</p>\n"; }

Set this trigger to fire before the output document step. Then, place @#fileContent in the output document template. When the output document is generated while running a case, the content will automatically be inserted depending on the system language.

The other option is to create a separate output document for each language. Add each output document as steps in the task. Then, add conditions to execute the one output document which corresponds to the current system language and not execute the rest of the output documents.

For example, output document templates are created for both Spanish and English:

Both output documents are added as steps in a task and conditions are added to both to check the current system language.

The following condition executes the Spanish output document:

(@@SYS_LANG == 'es' or @@SYS_LANG == 'es-ES')

And the following condition would execute the English output document step if the system language is not Spanish: (@@SYS_LANG != 'es' and @@SYS_LANG != 'es-ES')

Inserting Output Documents into a Process

After creating an output document, decide where in a process the output document can be submitted. Remember that a task is a group of steps, so an output document must be added in a task. Read this documentation which explains how to add an output document as a step.

Output Documents Example

Simple Output Documents Example

To create simple output documents, go to Output Documents in the main toolbox and click on Create. A new window will open where the information about the document must be filled in. After filling in all the necessary information, save the output document.

Once saved, the "Output Document Example" will appear in the Output Documents list, click on Open Editor to write a document in a Word-like environment. After it is saved, a quick message will appear saying the document has been edited successfully.

After saving it, go to the first task and right click on it to select Steps, then drag and drop the "Output Documents Example" to be shown after the Dynaform.

Now, to see what an output document looks like when a case is running, go to Home > New Case and double click on the process that contains the output document. In this case, the process "Copy of Purchase Request" is being used as an example. Once the initial information about the client is filled in, the next step is to view the document. As the image below shows, the document is generated in .doc and .pdf.

The image below shows how both documents look in both .doc and .pdf formats.

Output Documents Example with HTML

To create an example with HTML, first create four variables: "name" (String), "email" (String), "address" (String) and "currentDate" (Datetime). These variables will be stored in all the fields of the Dynaform that we will create next.

Now, create a Dynaform with fields that have names corresponding to the variable, the Dynaform and the soon to be created output document. Don't forget to create a Submit button to go onto the next task.

Save the Dynaform "Order request form" to add it as a step in the task that will be worked on.

It's time to create an output document with the name "Output Documents Example". Locate the HTML button and click on it. It will open an HTML Source Editor where code can be added. Try adding this code for this particular example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<p></p>
<div style="font-family: 'Trebuchet MS', Arial, Helvetica, sans-serif; font-size: 13px;">
<p><img src="http://www.processmaker.com/uploads/processmaker_logo_nobg300.png" width="300" height="72" /></p>
<p style="color: #009; font-weight: bold;">NEW YORK<br />Brooklyn, NY, 11238, USA</p>
<p style="text-align: center; text-decoration: underline; font-size: 20px;">PROOF OF PAYMENT</p>
<p>Sent by: @#USR_USERNAME</p>
<p>Name: @#name</p>
<p>Email: @#email</p>
<p>Address: @#address</p>
<p>Current date: @#currentDate</p>
<p>Status: Approved</p>
<p></p>
</div>
</body>
</html>
</body>
</html>

When the code is ready to be executed click on Update to save it.

The result of this HTML Code will be:

This example was designed to use variables that will automatically display the saved responses from the Dynaform fields in the Output Document. Go to the variable picker in the Output Document editor, and choose the prefix "@#" to insert the value of the variable without any changes. Insert the variables that belong to each field, as seen in the image below.

After adding all the variables to each field, the output document is ready to be assigned to a task. Save it, and it will appear in the list with the other Output Documents.

Choose the first task and right click on it to show its properties, then click on Steps to add the output document after completing the Dynaform, as seen in the image below.

To test if it works, go to Home > New Case and start the process "Copy of Purchase Request" by double clicking it. Fill the information in the form and click Submit to see the output document.

The next window will show that there is an output document before moving on to the next task, and that there are two files generated in .doc and .pdf.

Once Open is clicked for either document, an automatic download of the output documents will start and will be saved in the Download folder. Open them to see that the document has the information required in the HTML Code and is calling all the variables added in the Dynaform.

Restrict Output Document Links

When an output document is generated inside a process, one or two links are generated to download and/or open the output document depending on the output document configuration.

To restrict these output document links, configure the disable_download_documents_session_validation flag in the env.ini file of the workspace or the ProcessMaker instance.

disable_download_documents_session_validation= 0|1

If the flag is set to 1, the output document can be downloaded by any user with the link without restrictions.

If set to 0 or not set, the user needs to be logged in to ProcessMaker with a valid active session and have the right user permissions to download the document. Otherwise, the following message will be displayed when accessing the link:

Click the Login with other credentials button to be redirected to the ProcessMaker login page. ProcessMaker will not redirect the user to the link after the user with the right permissions logs in, therefore, it is necessary to enter the output document link into the browser URL bar again.

Output Document Storage

Output Document Definitions

The definitions of output documents are stored in the wf_<WORKSPACE>.OUTPUT_DOCUMENT table in the MySQL database. This table, also contains the title, description, template and filename for output documents.

To find information such as the title, description, template and filename for output document, enter MySQL (either from the command line or with a graphical program such as phpMyAdmin) or access it through a function such as executeQuery() in a trigger. Search for a value of 'OUT_DOC_TITLE', 'OUT_DOC_DESCRIPTION', 'OUT_DOC_TEMPLATE', and 'OUT_DOC_FILENAME' in the wf_<WORKSPACE>.OUTPUT_DOCUMENT table. For example, to find all output document templates:

SELECT OUT_DOC_UID, OUT_DOC_TITLE, OUT_DOC_DESCRIPTION, OUT_DOC_FILENAME, OUT_DOC_TEMPLATE FROM OUTPUT_DOCUMENT

To find a specific output document template, specify its unique ID in the query:

SELECT OUT_DOC_UID, OUT_DOC_TITLE, OUT_DOC_TEMPLATE FROM OUTPUT_DOCUMENT WHERE OUT_DOC_UID = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

To see all the information about a particular output document definition, search for its unique ID, which can either be found in the field wf_<WORKSPACE>.OUTPUT_DOCUMENT.OUT_DOC_UID or by opening the list of output documents inside ProcessMaker and clicking the Show ID link for an output document. Once the unique ID is known, it can be used in a SQL query:

SELECT * FROM OUTPUT_DOCUMENT WHERE OUT_DOC_UID = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

Output Document Files

When output document files are generated while running a case, an HTML file is created based upon the output document's template. From that HTML file, a PDF and/or DOC file are created. (Actually the DOC file is really just HTML code inside a DOC container.)

Output document files are stored at:

<INSTALL-DIRECTORY>/shared/sites/<WORKSPACE>/files/<CASE-UID>/outdocs/<CASE-FILE-UID>_<VERSION>.<EXTENSION>

The filename of output document files includes the unique ID for the case file (which is stored in the wf_<WORKFLOW>.APP_DOCUMENT.APP_DOC_UID field) and the version number, which starts counting from 1. Even if versioning isn't enabled, the filename will include "_1".

Linux/UNIX:

<INSTALL-DIRECTORY>/shared/sites/<WORKSPACE>/files/<CASE-UID>/outdocs/<CASE-FILE-UID>_<VERSION>.html /<CASE-FILE-UID>_<VERSION>.pdf /<CASE-FILE-UID>_<VERSION>.doc

Note: The TCPDF library doesn't generate a separate HTML file.

For example:

/opt/processmaker/shared/sites/workflow/files/a03459e1cb9824dac456780eca7b5cf6/outdocs/6663790024dd29d8bcb8212038377266_2.doc

Windows:

<INSTALL-DIRECTORY>\processmaker\shared\<WORKSPACE>\files\<CASE-UID>\outdocs\<CASE-FILE-UID>_<VERSION>.html \<CASE-FILE-UID>_<VERSION>.pdf \<CASE-FILE-UID>_<VERSION>.doc

For example in Windows Vista and later:

C:\Users\Bob\AppData\Roaming\ProcessMaker-2_5_3\processmaker\shared\workflow\files\a03459e1cb9824dac456780eca7b5cf6\outdocs\6663790024dd29d8bcb8212038377266_2.doc

In version 2.5.1 and later, an option was added to allow case files to be stored in a series of 3 subdirectories created from the case's unique ID to avoid the 32K file limits of Linux's ext3 file system. In version 3.0 and later, this option is activated by default. This means that a directory using the case's unique ID, such as /a03459e1cb9824dac456780eca7b5cf6/ in the above example, becomes 3 subdirectories whose names are three characters in the case's unique ID, with the rest of the unique ID placed in the name of another subdirectory:

/opt/processmaker/shared/sites/workflow/files/a03/459/e1c/b9824dac456780eca7b5cf6/outdocs/6663790024dd29d8bcb8212038377266_2.doc

If accessing an output document file from a ProcessMaker trigger or plugin, it is recommended to use the defined constant PATH_DOCUMENT, to set the location of the case files, such as "/opt/processmaker/shared/sites/workflow/files/" on a Linux/UNIX system, and PATH_SEP, which is "/" on Linux/UNIX systems and "\" on Windows systems to separate directories in the file system. The G::getPathFromUID() method may be used in version 2.5.1 or later to break a unique ID number into subdirectories in this way if the system requires it. For example, to get an output document file with the case-file ID of 6960198894e6927e0a40b14004833875 and the version number 2 in the current case:

$g = new G();
$OutDocPath = PATH_DOCUMENT . $g->getPathFromUID(@@APPLICATION) . PATH_SEP . "outdocs" . PATH_SEP . "6960198894e6927e0a40b14004833875_2.pdf";
If unsure if in version 2.5.1 or later, then use method_exists()to check whether G::getPathFromUID() exists before calling it.
$caseId = 'a03459e1cb9824dac456780eca7b5cf6';
$g = new G();
$caseIdPath = method_exists(G, "getPathFromUID") ? $g->getPathFromUID($caseId) : $caseId;
$OutDocPath = PATH_DOCUMENT . $caseIdPath . PATH_SEP . "outdocs" . PATH_SEP . "6960198894e6927e0a40b14004833875_2.pdf";

Changing the File Location

To store input and output document files in a different location, such as a NAS, then copy the contents of the files directory to the new location and then edit the source code in workflow/public_html/sysGeneric.php and change the location of PATH_DOCUMENT, which is defined in line 332:

 define( 'PATH_DOCUMENT', PATH_DATA_SITE . 'files/' );

For example, to store files on an NAS mounted drive at /media/nas/processmaker:

define( 'PATH_DOCUMENT', '/media/nas/processmaker/' );

Make sure to include the forward slash in Linux/UNIX or the backward slash in Windows at the end of the path.

Generated Output Documents in the Database

When an output document is generated when running a case, a new entry is added to the wf_<WORKSPACE>.APP_DOCUMENT table and a new unique ID is assigned to the generated Output Document. In addition, other entries like 'APP_DOC_TITLE','APP_DOC_FILENAME' and 'APP_DOC_COMMENT' are added to the table.

If inside a trigger or using an external application or script, the unique ID for an output document file can be found with the outputDocumentList() web service. Inside a trigger or a Dynaform, the unique IDs for all generated output documents can be looked up with the following SQL query:

SELECT APP_DOC_UID FROM APP_DOCUMENT WHERE APP_DOC_TYPE='OUTPUT' AND APP_DOC_STATUS='ACTIVE'

To find the generated output documents for a specified case:

SELECT APP_DOC_UID FROM APP_DOCUMENT WHERE APP_UID='<CASE-UID>'
   AND APP_DOC_TYPE='OUTPUT' AND APP_DOC_STATUS='ACTIVE'

To find a specific output document for a specified case, which was uploaded by a specified user:

SELECT APP_DOC_UID FROM APP_DOCUMENT WHERE APP_UID='<CASE-UID>'
   AND APP_DOC_TYPE='OUTPUT' AND APP_DOC_STATUS='ACTIVE'
   AND DOC_UID='<OUTPUT_DOC_UID>' AND USR_UID='<USER_UID>'

Output documents can be marked by tags, which provide an easy way to find related output documents under HOME > Documents. The tags are stored in the wf_<WORKSPACE>.APP_DOCUMENT.APP_DOC_TAGS field for each generated output document file and multiple tags are separated by commas. To find all generated output document files for a case with a specified tag:

SELECT APP_DOC_UID FROM APP_DOCUMENT WHERE APP_DOC_TYPE='OUTPUT'
   AND APP_DOC_STATUS='ACTIVE' AND APP_DOC_TAGS LIKE '%<TAG>%'

To find all generated output documents created between a certain date range:

SELECT APP_DOC_UID FROM APP_DOCUMENT WHERE APP_DOC_TYPE='OUTPUT'
   AND APP_DOC_CREATE_DATE>='<YYYY-MM-DD HH:MM:SS>' AND APP_DOC_CREATE_DATE<='<YYYY-MM-DD HH:MM:SS>'
   AND APP_DOC_STATUS='ACTIVE'

To find the unique IDs of all the generated files of a specified output document definition and their filenames used under HOME > Documents (not its real filename in the file system), query the wf_<WORKSPACE>.APP_DOCUMENT table:

SELECT APP_DOC_UID, APP_DOC_FILENAME FROM APP_DOCUMENT
   WHERE APP_DOC_STATUS='ACTIVE' AND APP_DOC_TYPE='OUTPUT'

To find the unique IDs of all the generated output documents of a specified user and their filenames used under HOME > Documents:

SELECT APP_DOC_UID, APP_DOC_FILENAME FROM APP_DOCUMENT WHERE USR_UID = '<USER-UID>'
   AND APP_DOC_STATUS='ACTIVE' AND APP_DOC_TYPE='OUTPUT'

To find the unique IDs of all the generated output documents of a specified case and their filenames used under HOME > Documents:

SELECT APP_DOC_UID, APP_DOC_FILENAME FROM APP_DOCUMENT WHERE APP_UID = '<CASE-UID>'
    AND APP_DOC_STATUS='ACTIVE' AND APP_DOC_TYPE='OUTPUT'

Accessing Output Document with Triggers

Links to Output Documents in Dynaforms

Trigger code can be used to look up information about an output document file in the database and construct the address to download the file.

First, add two link controls to a Dynaform for the PDF and DOC of an output document file:

In the properties of the link to the PDF file, set its display text property to the @@filenamePdf variable and set its href property to the @@filePdfUrl variable. Likewise, in the properties of the DOC file, set its display text property to the @@filenameDoc variable and set its href property to the @@fileDocUrl variable.

Then, create the following trigger, which looks up information about the latest version of the output document file in the APP_DOCUMENT table and its filename in the CONTENT table in the database:

//set to the ID of the Output Document:
$docId = '30671206456bbc811c7dd13078044406';
$caseId = @@APPLICATION;
$query = "SELECT APP_DOC_UID AS FILE_ID, APP_DOC_FILENAME, DOC_VERSION AS VERSION
          FROM APP_DOCUMENT WHERE APP_UID='$caseId' AND DOC_UID='$docId'
          AND APP_DOC_STATUS='ACTIVE' AND APP_DOC_TYPE='OUTPUT'
          ORDER BY DOC_VERSION DESC"
;
$result = executeQuery($query);

if (!is_array($result) or count($result) == 0) {
   die("Error: Unable to find Output Document file for case $caseId.");
}

$fileId = $result[1]['FILE_ID'];
$filename = $result[1]['FILENAME'];
$version = $result[1]['VERSION'];
@@filePdfUrl = "http://{$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']}/sys" . @@SYS_SYS .
   "/neoclassic/en/cases/cases_ShowOutputDocument?a=$fileId&v=$version&ext=pdf";
@@fileDocUrl = "http://{$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']}/sys" . @@SYS_SYS .
   "/neoclassic/en/cases/cases_ShowOutputDocument?a=$fileId&v=$version&ext=doc";
@@filenamePdf = "{$filename}_{$version}.pdf";
@@filenameDoc = "{$filename}_{$version}.doc";

This trigger code sets the values of the variables that are inserted into the properties of the link controls when the Dynaform is generated. Make sure to change the $docId to the unique ID of the output document. Then, set this trigger to fire before the Dynaform.

When a case is run, the filenames and the URLs of the PDF and DOC files should be automatically inserted into the links in the Dynaform.

Generating Output Documents

The PMFGenerateOutputDocument() function can be called in a trigger to generate an output document in the current case. The PMFGenerateOutputDocument() function doesn't return any information about the generated file, but afterwards the executeQuery() function can be used to look up this information in the wf_WORKSPACE.APP_DOCUMENT table. Information, such as the filename, file version, the user who generated the file, and datetime when generated, can be obtained with a complex database query as shown in the previous example, but it is much simpler to use the AppDocument::Load() method to obtain this information.

Example:

This example (which can be downloaded by right clicking this link and saving it) shows how to generate an output document and display a link to the generated file in a subsequent Dynaform, so a separate step to create an output document is not necessary.

First, create two string variables named outDocUrl and outDocFilename, which will be used to pass the web address and filename of the generated file to the Dynaform. Then, create a Dynaform that has a link control. In the properties of that link control, set the display text property to @@outDocFilename and the href property to @@outDocUrl.

Then, create an output document and get its Unique ID number by clicking on its Show ID button:

Then, create a trigger with the following code that generates the output document and looks up information about the generated PDF file:

//set to the Unique ID of the Output Document:
$outDocId = '84581368556d0b69010a355067195050';
$caseId = @@APPLICATION;

PMFGenerateOutputDocument($outDocId);

//retrieve info from the database about the generated output document file
$query = "SELECT APP_DOC_UID FROM APP_DOCUMENT WHERE APP_UID='$caseId' AND
   DOC_UID='$outDocId' AND APP_DOC_STATUS='ACTIVE'"
;
$result = executeQuery($query);

if (!is_array($result) or count($result) == 0) {
   die("Error: Unable to find generated Output Document in database.");
}

$d = new AppDocument();
$aFile = $d->Load( $result[1]['APP_DOC_UID'] );

//change from 'http://' to 'https://' if using SSL
//change 'pdf' to 'doc' for MS Word file
@@outDocUrl = 'http://' . $_SERVER['SERVER_NAME'] .
   // ':' . $_SERVER['SERVER_PORT'] . //uncomment if needing a port number
   '/sys'. @@SYS_SYS . '/en/neoclassic/cases/cases_ShowOutputDocument?a=' .
   $aFile['APP_DOC_UID'] . '&v='. $aFile['DOC_VERSION'] . '&ext=pdf';
@@outDocFilename = $aFile['APP_DOC_FILENAME'] .'_'. $aFile['DOC_VERSION'] .'.pdf';

Change the $outDocId variable to the output document's unique ID. The address in @@outDocUrl may also need to be adjusted if using https or if using a port number. In this example, the link is for a PDF file, but to link to an MS Word file change the file extension from .pdf to .doc. Set the above trigger to fire before the Dynaform.

When a case is run, the filename for the generated output document file should be displayed in the link field.

Convert Output Documents to Text Files

The following example shows how to convert an output document file into a text file and display it in a Link control in a subsequent Dynaform so the user can download the text file.

In this example, the pdftotext command from Poppler is used to convert an output document's PDF file into a text file. Poppler has to be installed separately on the ProcessMaker server. On most Linux/UNIX servers, it is available to be installed in the poppler-utils package. For Windows machines, Poppler can be downloaded here. To avoid installing a separate program, it is also possible to convert the output document's HTML file into text with the strip_tags() function, so this example can be modified to work without Poppler.

First, create an output document in the process and get its ID number, which in this example is "233815488585c62af61e2a6077136729".

Then, create a Dynaform with a Link control. In the Link properties, set the display text to @@textDocFilename and the href to @@textDocUrl.

Finally, create the following trigger:

//set to the Unique ID of the Output Document:
$outDocId = '233815488585c62af61e2a6077136729';
PMFGenerateOutputDocument($outDocId);

//retrieve info from the database about the generated output document file
$caseId = @@APPLICATION;
$query = "SELECT APP_DOC_UID, DOC_VERSION FROM APP_DOCUMENT
   WHERE APP_UID='$caseId' AND DOC_UID='$outDocId' AND
   APP_DOC_STATUS='ACTIVE' ORDER BY APP_DOC_CREATE_DATE DESC"
;
$result = executeQuery($query);
if (!is_array($result) or count($result) == 0) {
   die("Error: Unable to find generated Output Document in database.");
}
//get the filename of the uploaded document:
$d = new AppDocument();
$aFile = $d->Load($result[1]['APP_DOC_UID'], $result[1]['DOC_VERSION']);
$originalFilename = $aFile['APP_DOC_FILENAME'].'_'.$aFile['DOC_VERSION'];
$filename = $result[1]['APP_DOC_UID'].'_'.$result[1]['DOC_VERSION'];

$g = new G();
$path = PATH_DOCUMENT. $g->getPathFromUID($caseId) .PATH_SEP. "outdocs" .PATH_SEP. $filename .'.pdf';

$tempFile = tempnam(sys_get_temp_dir(), $originalFilename.'_');
//convert PDF to text file:
exec("pdftotext $path $tempFile.txt", @=aOutput);

//upload temporary text file to current case
$params = array (
   'ATTACH_FILE'  => new CurlFile($tempFile.'.txt'),
   'APPLICATION'  => @@APPLICATION,
   'INDEX'        => @%INDEX,
   'USR_UID'      => @@USER_LOGGED,
   'DOC_UID'      => '-1',
   'APP_DOC_TYPE' => 'ATTACHED',
   'TITLE'        => '',
   'COMMENT'      => ''
);

$domain = ($g->is_https() ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'];
//add if needing a port number: .':'. $_SERVER['SERVER_PORT']
$uploadUrl = $domain.'/sys'.SYS_SYS.'/'.SYS_LANG.'/'.SYS_SKIN.'/services/upload';

//upload text file created from output document
ob_flush();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uploadUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
// curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 1); //Uncomment for SSL
// curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 1); //Uncomment for SSL
$response = curl_exec($ch);
curl_close($ch);
//delete temporary text files:
unlink($tempFile);
unlink($tempFile.'.txt');

if (strpos($response, 'uploaded successfully') === false) {
   die($response);
}

//lookup uploaded text file in the database:
$query = "SELECT APP_DOC_UID, DOC_VERSION FROM APP_DOCUMENT
   WHERE APP_UID='$caseId' AND DOC_UID='-1' AND APP_DOC_STATUS='ACTIVE'
   ORDER BY APP_DOC_CREATE_DATE DESC"
;
$result = executeQuery($query);

@@textDocUrl = $domain.'/sys'.SYS_SYS.'/'.SYS_LANG.'/'.SYS_SKIN.
    '/cases/cases_ShowDocument?a='. $result[1]['APP_DOC_UID'] .
    '&v='. $result[1]['DOC_VERSION'];
@@textDocFilename = basename($tempFile.'.txt');

Change the ID number of the output document to match your process. Set this trigger to execute before the Dynaform.

This trigger first uses PMFGenerateOutputDocument() to create the output document files. Then, it searches for the newly generated file in the APP_DOCUMENT table in the database to get its unique ID and version number. With that information, it calls the AppDocument::Load() method to get the filename of the generated file and construct the path where the file is stored on the ProcessMaker server.

The trigger then uses the tempnam() function to create a temporary file on the ProcessMaker server that will hold the text file. Then, it uses the exec() function to make a system call for the pdftotext program to convert the output document's PDF file into a text file.

The temporary text file is then uploaded to /services/upload as a new document in the case. The APP_DOCUMENT table is queried again to find the ID number and version number of this new document file. The URL to download the text file is placed in the @@textDocUrl variable and the filename of the text file is placed in the @@textDocFilename variable.

When a case is run and the Dynaform with the Link field is displayed, the user can click on the link to download the text file.

For a sample process containing this code, download and install output_document_to_text_file-3.pmx (right click and select "Save Link As").