Generating PDF/UA from Excel templates
This guide explains how to generate an Excel workbook from a template and convert the generated file to PDF/UA with Nutrient Java SDK.
PDF/UA supports accessible PDF output for assistive technologies such as screen readers. Use it when generated documents have to align with standards and policies such as Section 508, ADA, or EN 301 549.
Use this workflow for the following workbook types:
- Invoices and billing statements.
- Financial reports and summaries.
- Price lists and catalogs.
- Repeated workbooks with structured template data.
Using the Java SDK for template-to-PDF/UA generation
Use one Excel template, apply JSON data, and export accessible PDF output.
Template generation helps you separate the following parts of the document workflow:
- Worksheet design, formulas, and formatting in the Excel template.
- Variable content in the JSON data model.
- Output generation in the Java application.
- PDF/UA conformance in the export settings.
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.SpreadsheetEditor;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 SpreadsheetTemplateToPDFUA{Create a main method and declare the exceptions used in this sample:
public static void main(String[] args) throws NutrientException, IOException {Then add the template processing and export workflow.
Processing the Excel template
Use a try-with-resources statement(opens in a new tab) to close resources correctly.
Open the Excel template document:
try (Document document = Document.open("input_spreadsheet.xlsx")) {Create a SpreadsheetEditor instance for template operations:
SpreadsheetEditor editor = SpreadsheetEditor.edit(document);Loading and applying the template data
Load the JSON model that populates the template placeholders:
String model = Files.readString(Path.of("input_spreadsheet_model.json"));Apply the model to replace placeholders with data:
editor.applyTemplateModel(model);This call handles the following template processing tasks:
- Parse placeholders and merge fields.
- Replace content while preserving formatting.
- Repeat rows for collection data.
- Maintain cell types, structure, and styles.
Save the processed workbook as an intermediate Excel file:
editor.saveWithModelAs("output.xlsx"); editor.close(); }At this point, output.xlsx contains the populated workbook.
Converting to accessible PDF/UA format
Open the processed document before configuring the PDF export settings:
try (Document processedDoc = Document.open("output.xlsx")) {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"); } }}The workflow creates an intermediate Excel workbook (output.xlsx) and a final PDF/UA file (output.pdf).
Understanding the complete workflow
This sample uses the following workflow:
- Template design — Create an Excel template with placeholders for dynamic content.
- Data preparation — Structure JSON data to match the template fields.
- Template processing — Apply JSON data to generate Excel output.
- Accessibility conversion — Convert Excel output to PDF/UA.
- Compliance check — Validate output against your accessibility requirements.
This approach enables template authors to work in Excel while developers generate consistent, accessible output programmatically.
Error handling
The SDK uses exceptions for error handling. The methods in this guide throw the following exceptions:
NutrientExceptionfor SDK-related errors during template processing or PDF conversion.IOExceptionfor file-reading errors when loading the JSON model.
Handle these exceptions in your app for logging, retries, or fallback logic.
Conclusion
You now have a template-to-PDF/UA workflow for Excel workbooks. Use this pattern to:
- Process Excel templates with dynamic data.
- Generate intermediate Excel workbooks for review.
- Produce accessible PDF/UA documents for distribution.
- Check generated files against accessibility requirements.
- Maintain consistency across generated workbooks.
Download the sample package to run this example as-is.