Some test text!

Loading...
Guides
Overview

Document Generation via Template in Android

Overview

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.

Launch Online Demo

PDFTron benefits include:

  • Securely merge data directly in your application. No need to share confidential data with anyone!
  • Use familiar tools (any word processor such as MS Word or Google Docs) to design professional looking templates with ease.
  • Avoid vendor lock-in with open-standard Office format and leverage existing collections of ready to use templates.
  • Prevent server bottlenecks by generating documents on the fly directly in the browser
  • Embed the document viewing experience directly into your solution.
  • Combine top quality PDF generation of your templates with the market leading PDFTron SDK.
  • 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.

Get Started Sample API Docs

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)
PDFDoc doc = new PDFDoc();

// 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.
OfficeToPDFOptions options = new OfficeToPDFOptions();
options.setTemplateParamsJson(json_data_string);

// perform the conversion with the template replacement data
Convert.officeToPdf(doc, filename, options);

Examples

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.

{
	"tblh1":"Services",
	"tblh3":"Charge",
	"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
To find out more details about the specification about the data model

Live Web Sample
To try a live sample of template filling using our WebViewer

Get the answers you need: Support

UPCOMING WEBINAR: "2021 in review: Top five new & updated features" Dec 9th @ 11am PT