Some test text!


Document Generation via Template on iOS


PDFTron's office template generation framework enables the dynamic generation of PDFs: you provide a template in the form of an Office document and replacement data in json form, and PDFTron SDK will efficiently generate a PDF.

  • Make use of existing authoring tools (MS Office, Google docs, etc.) to create your templates, with no plugins or extra tools required.
  • Generated documents retain the style of the original document.
  • Seamless text reflow and pagination, even around figures and images.
  • All the advanced document features that Word, Powerpoint, and Excel documents can offer.
  • Self-contained, with no third-party dependencies.
  • Generated PDFs have automatically generated accessibility tags.

Easy to use

The generation framework requires minimal code to get up and running. Simply initiate a normal Office conversion, but with the optional TemplateParamsJson parameter set:

// Start with a PDFDoc (the conversion destination)
PTPDFDoc* doc = [[PTPDFDoc alloc] init];

// create an options object and add your template
// replacement values to it. If this option is not
// set, the document will convert as if it is a normal
// office documents, with no template generation.
PTOfficeToPDFOptions* options = [[PTOfficeToPDFOptions alloc] init];
[options SetTemplateParamsJson:json_data_string];

// perform the conversion with the template replacement data
[PTConvert OfficeToPDF:doc in_filename:filename options:options];


The following are a series of real examples, generated using the code above. For each example, the template source and the json data source are included below, so that you can try them out yourself.

Simple replacement (.docx, .json)

Here's a really minimal example: a very simple template document, with a single text replacement value.

    "short_text": "Lorem ipsum dolor, .etc"

Generating styled text (.docx, .json)

To add styles to the template, simply set the style of the template text as desired:

    "short_text": "Lorem ipsum dolor, .etc"

Automatic reflow (.docx, .json)

Text reflows according to the rules set in the original template file, and will automatically generate extra pages if needed. Make use of column layouts and justification rules:

    "legal_heading":"End-User Agreement",
    "indemnification_clause":"Sed ut unde omnis iste natus error sit volup tatem...",
    "escrow_clause":"Lorem ipsum dolor sit amet, consec  tetuer adipi scing elit...",
    "arbitration_clause":"pretium quis, sem. Nulla conse quat massa quis enim. D...",
    "confidentiality_clause":"idunt. Cras dapibus. Vivamus elem entum semper nis..."

Reflow around figures (.docx, .json)

Automatically flow text around obstacles according to the template.

    "long_text": "Sed ut perspiciatis unde omnis iste natus..."

Dynamic tables (.docx, .json)

Dynamically insert rows into tables using the insert_rows value specifier. Especially useful for invoice generation or itemized lists.

    "billed_items": {"insert_rows": [["Wireless", "", "$42.34"], "..."]},
    "totals": {"insert_rows": [["", "Tax:", "$8.37"],["", "Balance:","..."]]}

Insert images (.docx, .json)

Insert images into the text at any location using the image_url value specifier. Images can be resized as desired, and inserted at any position in the original document.

    "logo":{"image_url":"./logo_red.png", "width":40, "height":40}

Further Reading

For more information, see the following resources:

Detailed specification of the template generation data model

Get the answers you need: Support


Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.