Word template processing-to-PDF/UA conversion
Use this workflow to generate Word documents from templates and convert them to PDF/UA.
PDF/UA is designed for accessible PDF output and supports assistive technologies such as screen readers. This is useful when documents align with standards and policies such as Section 508, ADA, or EN 301 549.
Common use cases include:
- Contracts and agreements
- Reports and statements
- Invoices and notices
- Any repeated document with structured template data
Use the Java SDK for template-to-PDF/UA generation
Use one source Word template, apply JSON data, and export accessible PDF output.
Template generation helps you:
- Separate content from design
- Keep formatting consistent across generated files
- Reduce manual copy-and-paste errors
- Generate personalized documents from the same template
PDF/UA conversion adds:
- Accessible output for assistive technologies
- Semantic structure for navigation
- Compliance-ready export format
- A stable format for distribution and archiving
Preparing the project
Define a package and import the classes required for template processing and PDF/UA conversion:
package io.nutrient.Sample;
import io.nutrient.sdk.Document;import io.nutrient.sdk.editors.WordEditor;import io.nutrient.sdk.enums.PdfConformance;import io.nutrient.sdk.exceptions.NutrientException;import io.nutrient.sdk.settings.PdfSettings;
import java.io.IOException;import java.nio.file.Files;import java.nio.file.Path;
public class WordTemplateToPDFUA{Create a main method and declare the exceptions used in this sample:
public static void main(String[] args) throws NutrientException, IOException {Then add the SDK-specific workflow.
Processing the Word template
Use a try-with-resources statement(opens in a new tab) to close resources correctly.
Open the Word template document:
try (Document document = Document.open("input_template.docx")) {Create a WordEditor instance for template operations:
WordEditor editor = WordEditor.edit(document);Loading and applying the template data
Load the JSON model used to populate placeholders:
String model = Files.readString(Path.of("input_template_model.json"));Apply the model to replace placeholders with data:
editor.applyTemplateModel(model);This call handles template processing tasks such as:
- Parsing placeholders and merge fields
- Replacing content while preserving formatting
- Handling repeating or conditional sections
- Maintaining document structure and styles
Save the processed document as an intermediate Word file:
editor.saveWithModelAs("output.docx"); editor.close(); }You now have a processed Word document with populated template content.
Converting to accessible PDF/UA format
Open the processed document for conversion:
try (Document processedDoc = Document.open("output.docx")) {Set PDF settings for PDF/UA conformance:
PdfSettings pdfSettings = processedDoc.getSettings().getPdfSettings(); pdfSettings.setConformance(PdfConformance.PDF_UA_1);Export the document as an accessible PDF:
processedDoc.exportAsPdf("output.pdf"); } }}You now have an intermediate Word document (output.docx) and a final PDF/UA file (output.pdf).
Understanding the complete workflow
This sample uses the following workflow:
- Template design — Create Word templates with placeholders for dynamic content
- Data preparation — Structure JSON data to match template fields
- Template processing — Apply JSON data to generate Word output
- Accessibility conversion — Convert Word output to PDF/UA
- Compliance assurance — Validate output against accessibility requirements
This approach enables template authors to work in Word while developers automate consistent, accessible output.
Error handling
The SDK uses exceptions for error handling. The methods in this guide can throw:
NutrientExceptionfor SDK-related errors during template processing or PDF conversionIOExceptionfor file-reading operations when loading the JSON model
Handle these exceptions in your app for logging, retries, or fallback logic.
Conclusion
You now have a complete template-to-PDF/UA flow. This pattern enables you to:
- Process Word templates with dynamic data
- Generate intermediate Word documents for review if needed
- Produce fully accessible PDF/UA documents for distribution
- Ensure compliance with accessibility regulations
- Maintain consistency across all generated documents
Download the sample package to run this example as-is.