Some test text!
Web / Guides / Overview
Apryse's office template generation framework enables the dynamic generation of PDFs:
The generation framework requires minimal code to get up and running. Either class applyTemplateValues
to the currently loaded document or pass in templateValues
when calling office2PDFBuffer
.
WebViewer(...)
.then(instance => {
instance.loadDocument('template-document.docx', {
officeOptions: {
doTemplatePrep: true
}
});
const { documentViewer } = instance.Core;
documentViewer.on('documentLoaded', () => {
const doc = documentViewer.getDocument();
// it is possible to extract document template keys in WebViewer
const keys = doc.getTemplateKeys();
// create an options object and add your template
// replacement values to it
const options = {};
for (const i in keys) {
options[keys[i]] = json_data_string;
}
// apply the template values to the currently loaded document in WebViewer
await documentViewer.getDocument().applyTemplateValues(options);
});
});
Alternatively, without a viewer:
Core.office2PDFBuffer(documentPath, {
officeOptions: {
templateValues: {
// keys and values here
}
}
}).then(buffer => {
saveByteArray('generated_document.pdf', buffer);
});
Sample Code API Docs Template Specification
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.
Tags in the template document are replaced with a string from the supplied JSON. To control the style of the text, simply modify the style of the template tag as desired:
{
"short_text": "Lorem ipsum dolor, .etc"
}
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. This example uses a list loop with dynamic item renumbering.
{
"legal_heading":"End-User Agreement",
"legal_clauses": [
{"legal_clause":"Sed ut unde omnis iste natus error sit volup tatem..."},
{"legal_clause":"Lorem ipsum dolor sit amet, consec tetuer adipi s..."},
{"legal_clause":"pretium quis, sem. Nulla conse quat massa quis eni..."},
{"legal_clause":"idunt. Cras dapibus. Vivamus elem entum semper nis..."}
]
}
Dynamically insert or remove rows into tables using loops and conditionals. Table formatting such as row bands are updated. Especially useful for invoice generation.
{
"items": [
{"item": "Wireless", "charge": "$42.34"},
{"item": "Long Distance", "charge": "$12.55"},
{"item": "Data", "charge": "$14.89"}
],
"balance":"$12.52",
"total_due":"$82.30",
}
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}
}
Automatically flow text around obstacles according to the template.
{
"long_text": "Sed ut perspiciatis unde omnis iste natus..."
}
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
Advanced features
For a specification of advanced features, and greater detail on behavior
Live Web Sample
To try a live sample of template filling using our WebViewer
Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales