In many enterprise scenarios, generating documents is not just about producing a PDF. It’s about producing a structured, accessible, and reliable output that integrates seamlessly with existing systems.
In a recent project, I implemented a complete PDF generation pipeline triggered from Power Pages, orchestrated through Power Automate, and finalized using an Azure Function for advanced document processing.
This article walks through the architecture, key decisions, and lessons learned from building this solution.
The Problem
The requirement seemed straightforward at first:
- Generate a PDF from a submission in Power Pages
- Support multiple submission types and languages
- Ensure accessibility compliance
- Allow triggering from both Power Pages and Dynamics 365
However, standard approaches quickly showed limitations, especially around formatting and accessibility.
Why the Standard Approach Falls Short
Using Power Automate alone (Word templates + Convert to PDF action) introduces several issues:
- Flattened content (checkboxes and structured elements become plain text)
- Limited support for repeating sections (especially nested data)
- Accessibility issues (screen readers interpret content incorrectly)
- Loss of semantic structure in the final PDF
For basic documents, this works. For enterprise-grade and accessibility-compliant outputs, it doesn’t.
Solution Overview
To address these limitations, I designed a hybrid architecture combining Power Platform with Azure Functions.
High-Level Flow

- Power Pages triggers a Power Automate flow via JavaScript
- The flow receives parameters (RecordId, Language)
- A core subflow determines the correct Word template
- The template is populated dynamically
- The document is sent to an Azure Function
- Azure Function applies OpenXML fixes and converts to PDF
- Base64 PDF is returned and downloaded by the client
Architecture Breakdown
1. Power Pages (Frontend Trigger)
A JavaScript call triggers the flow using an HTTP endpoint:
- Passes parameters like
RecordIdandLanguage - Supports multilingual document generation
- Also reusable from Dynamics 365 via a ribbon button
- The request first goes through built-in Power Pages security checks before invoking the backend flow
This keeps the frontend lightweight and delegates processing to backend services.
2. Power Automate (Orchestration Layer)
Two flows are used:
- Portal Flow (entry point)
- Core Flow (processing logic)
Responsibilities include:
- Selecting the correct Word template based on submission type and language
- Populating the template using dynamic data
- Handling environment-specific configuration
- Calling the Azure Function using Entra ID and OAuth for secure authentication
- Ensuring that requests coming from Power Pages are validated through the portal flow before reaching the core processing logic
Templates are stored in a service account OneDrive, ensuring consistency across environments.
3. Word Template Strategy
Templates were designed using:
- Plain text content controls
- Repeating section controls for tabular data
- Placeholder tokens for calculated values (e.g., totals)
However, due to Power Automate limitations:
- Complex nested structures were avoided
- Some formatting was deferred to post-processing
4. Azure Function (The Critical Piece)
This is where the real transformation happens.
The Azure Function:
- Receives the generated Word document
- Uses OpenXML to:
- Fix bullet lists (convert plain text into structured lists)
- Improve checkbox representation
- Restore semantic structure for accessibility
- Converts the document to PDF using a third-party library (e.g., Aspose)
- Returns the PDF as Base64
This step ensures the final output is:
- Structurally correct
- Accessible
- Visually consistent
5. Response Handling
The flow returns a Base64-encoded PDF to the frontend.
On the client side:
- JavaScript immediately triggers a download
- No intermediate storage required
This results in a seamless user experience.
Key Design Decisions
Separation of Concerns
- Power Automate handles orchestration
- Azure Function handles transformation and conversion
This keeps each component focused and maintainable.
Accessibility First
Instead of fixing accessibility after generation, the solution embeds it into the pipeline:
- Structured lists instead of plain text
- Proper handling of semantic elements
- Screen-reader-friendly output
Reusability Across Channels
The same backend logic supports:
- Power Pages (external users)
- Dynamics 365 (internal users)
This avoids duplication and ensures consistency.
Lessons Learned
1. Power Automate Is Not Enough for Complex Documents
It’s great for orchestration, but limited for document fidelity and accessibility.
2. Post-Processing Is Essential
Using OpenXML after template population gives full control over structure.
3. Accessibility Requires Intentional Design
You can’t rely on default tools to produce accessible PDFs. You need to actively shape the output.
4. Environment Configuration Matters
Things like:
- Template storage (OneDrive paths)
- Azure Function endpoints
- Authentication setup
…must be carefully managed across Dev, QA, UAT, and Prod.
When to Use This Approach
This architecture is ideal when:
- Documents must be accessible (WCAG compliant)
- Output structure matters (lists, tables, checkboxes)
- Templates vary by language or type
- The solution must scale across multiple environments
Final Thoughts
What started as a simple “generate PDF” requirement quickly evolved into a full document processing pipeline.
By combining Power Platform with Azure Functions, it’s possible to go beyond basic automation and deliver enterprise-grade, accessible, and maintainable document solutions.
If you’re working with Power Pages or Dynamics 365 and need reliable document generation, this approach is worth considering.
