This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/python/templates/spreadsheet-template-to-pdf-ua.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Excel to PDF/UA | Nutrient Python SDK

This guide explains how to generate an Excel workbook from a template and convert the generated file to PDF/UA with Nutrient Python SDK.

Use this workflow for invoices, financial reports, statements, and other workbooks that use a fixed worksheet design with variable content. PDF/UA helps generated PDFs meet accessibility requirements for assistive technologies such as screen readers.

Download sample

Generating a workbook and exporting PDF/UA

Nutrient Python SDK handles the template processing and PDF/UA export workflow. The sample performs the following tasks:

  • Open an Excel template.
  • Load a JSON data model.
  • Apply the data model to replace placeholders.
  • Configure PDF/UA conformance.
  • Export the generated document as a PDF.

Complete implementation

The following sections build the complete Python example. First, import the classes required for document processing, template editing, PDF conformance, and error handling:

from nutrient_sdk import Document
from nutrient_sdk import SpreadsheetEditor
from nutrient_sdk import PdfConformance
from nutrient_sdk import NutrientException

Open the Excel template file. The context-manager(opens in a new tab) syntax closes the document when processing finishes:

def main():
try:
with Document.open("input_spreadsheet.xlsx") as document:

Create a SpreadsheetEditor instance for template processing:

editor = SpreadsheetEditor.edit(document)

Read the JSON data model that contains the values for the template placeholders:

try:
with open("input_spreadsheet_model.json", "r") as f:
model = f.read()
except IOError:
print("Failed to read template model file")
return

Apply the template model, save the generated workbook, and close the editor:

editor.apply_template_model(model)
editor.save()
editor.close()

Configure PDF/UA conformance and export the document as an accessible PDF:

# Configure PDF settings for PDF/UA conformance
pdf_settings = document.settings.pdf_settings
pdf_settings.conformance = PdfConformance.PDF_UA_1
document.export_as_pdf("output.pdf")
print("Successfully generated accessible PDF from template")
except NutrientException as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()

Conclusion

The template processing workflow consists of five steps:

  1. Open the Excel template.
  2. Create a spreadsheet editor.
  3. Apply the JSON template model.
  4. Configure PDF/UA conformance.
  5. Export the generated workbook as a PDF.

Use this pattern when you have a fixed Excel worksheet design and variable content from a data model.

Download the sample package to run this example as-is.