Creating a PDF template

Advantages of using PDF templates:

  • Can produce PDF files.

Disadvantages in comparison with text templates:

  • Produce larger documents.
  • More difficulty maintaining the templates over time.
  • More time is needed to create the document (especially when the PDF optimization configuration parameter is enabled).

You can create PDF template forms with several applications:

Every PDF form field name needs to be unique; you can't set the same property value for several form fields.

When converting an OpenOffice document to PDF, repeated form fields are renamed to original_name_2, original_name_3, etc.

If you need to put the same property value in several fields, try Creating LibreOffice templates.

In the sample below, we've used OpenOffice to create a PDF template.

Preliminaries

Register the Metadata group definition at Administration > Metadata.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE property-groups PUBLIC "-//OpenKM//DTD Property Groups 3.10//EN"
                                 "http://www.openkm.com/dtd/property-groups-3.10.dtd">
<property-groups>
  <property-group label="Sample Template" name="okg:tpl">
    <input label="Name" name="okp:tpl.name"/>
    <input label="Birth Date" name="okp:tpl.birth_date" type="date" />
    <select label="Language" name="okp:tpl.language" type="simple">
      <option label="Java" value="java"/>
      <option label="Python" value="python"/>
      <option label="PHP" value="php" />
    </select>
  </property-group>
</property-groups>

In order to create a relationship between the template form field and the property group, you must name them using the following naming convention: replace ":" and "." with "_". Here you can see the matching between both fields:

Metadata field nameTemplate field nameTemplate field value

okp:tpl.name

okp_tpl_name

${okp_tpl_name!}

okp:tpl.birth_date

okp_tpl_birth_date

${okp_tpl_birth_date!}

okp:tpl.language

okp_tpl_language

${okp_tpl_language!}

Creating the template

To create a template in OpenOffice.org, go to View > Toolbars > Form Controls.

A new dialogue will appear, and you will be able to add form elements to the document. This dialogue contains elements such as labels, text boxes, check boxes, etc.

Once the form has been created, go to File > Export as PDF to generate a PDF with these form fields. This is the final result:

Here is the generated PDF file tpl.pdf and the ODT source tpl_pdf.odt.

Date format

OpenKM uses FreeMarker internally, so you can take advantage of FreeMarker's formatting features. For example, you can set the date format in this way:

${okp_tpl_birth_date?string("yyyy-MM-dd")}

Learn more about FreeMarker formatting at Built-in Reference.  

Sample configuration

  • Upload the tpl.pdf file to /okm:templates/documents
  • Register metadata definition okg:tpl in Administration > Metadata 
  • Enable metadata from profiles in Administration > Profiles 
  • Add metadata group okg:tpl to the tpl.pdf file.