Generate Word and PDF Document From a template - Document output preview

Copilot Studio Document Generation: Create Word & PDF from Template

No comments

Loading

Introduction

Automating document creation is one of the most powerful use cases of AI today. With Microsoft Copilot Studio, you can perform Copilot Studio document generation to create Word and PDF files dynamically from a template.

Instead of manually preparing invoices, you can generate them instantly using structured input and AI-driven automation.

What You Will Learn

In this guide, you will learn how to:

  • Generate Word documents from a template
  • Automate invoice creation using Copilot Studio
  • Save documents to Microsoft SharePoint
  • Convert Word documents into PDF
  • Return downloadable files to users

I will pass the sample prompt below in my Copilot Studio agent, which will generate an invoice file in both PDF and Microsoft Word formats.

Hi, please create an invoice.

The invoice date is August 1, 2026.

The customer is Liam Anderson, located at 500 Elm Street in Seattle, Washington. His phone number is 9123456789.

Please ship the items to Liam Anderson from CloudCore Inc at the same address in Seattle, Washington. The shipping contact number is 9123456789.

Add the following items:
- 2 units of Cloud Deployment Service priced at 250 each (total 500)
- 1 unit of Premium Support Subscription priced at 300 (total 300)

The subtotal is 800, the tax is 80, and the shipping cost is 20. The total amount due is 900.

Add a comment that payment is due within 10 days.
Generate document in Copilot Studio using template
Generate document in Copilot Studio using template

Dynamic PDF Invoice Generated by Copilot Studio Agent:

Generate pdf document in Copilot Studio using template demo
Create pdf document in Copilot Studio using template demo

Create PDF document in Copilot Studio using template demo

Dynamic Word Invoice Generated by Copilot Studio Agent:

Create word document in Copilot Studio using template demo
Generate word document in Copilot Studio using template demo

Generate word document in Copilot Studio using template demo

Solution Overview

User → Agent → Prompt → Generate Document → Save to SharePoint → Return File

How to Generate Document Using Copilot Studio Step by Step

Step 1: Prepare Your Word Template

Before starting, you need a properly structured Word template.

If you haven’t created one yet, follow this guide on Word invoice template creation in Microsoft Word to set up your template correctly.

Your template should include placeholders like:

{{INVOICENUMBER}}, {{CustomerName}}, {{items.quantity}}, {{TotalAmount}}

Step 2: Create a Prompt

In Microsoft Copilot Studio:

👉 Go to Tools → Prompt

Configure Inputs:

  • InvoiceNumber (string)
  • UserInput (string)

Step 3: Add Prompt Instruction

Create an invoice document using the provided template.

InvoiceNumber is: {InvoiceNumber}

Use the following user input to fill the remaining details:

 {UserInput}

Ensure all placeholders are filled, including customer details, shipping details, items, subtotal, tax, shipping, and total amount.

Always generate a valid document with line items.

The instruction should look like below:

Instructions in Copilot Studio Prompt configuration
Instructions in Copilot Studio Prompt configuration

Step 4: Configure Sample Data in the Prompt Instructions

Configure sample data for the invoice number and user inputs.

Invoice Number Sample Data:

Configure sample data in prompt instruction invoice number
Configure sample data in prompt instruction invoice number

User Input Sample Data:

Create an invoice with the following details:

INVOICEDATE is August 1, 2026

CustomerName is Liam Anderson
CustomerAddress is 500 Elm Street
CustomerCity is Seattle, Washington
CustomerPhone is 9123456789

ShipName is Liam Anderson
ShipCompany is CloudCore Inc
ShipAddress is 500 Elm Street
ShipCity is Seattle, Washington
ShipPhone is 9123456789

Items:
- quantity: 2, description: Cloud Deployment Service, unitPrice: 250, total: 500
- quantity: 1, description: Premium Support Subscription, unitPrice: 300, total: 300

Subtotal is 800
Tax is 80
Shipping is 20
TotalAmount is 900

Comments is Payment due within 10 days
Configure sample data in prompt instruction user input
Configure sample data in prompt instruction user input

Step 5: Select Output Type

👉 Choose:

Document Preview

This is required for document generation in Copilot Studio.

Create document using Document preview feature in Copilot Studio
Create document using Document preview feature in Copilot Studio

Click on “Document Settings” and upload your document generation template file.

If your template is configured correctly, all the dynamic fields from your invoice document will be automatically detected or identified.

Extraction of Document Template Dynamic fields
Extraction of Document Template Dynamic fields

Now, let’s test the invoice document generation template. Click on the “Test” button in the top-right corner.

You will see that all the sample invoice data values are automatically mapped to their respective fields. This confirms that the invoice document generation template is ready to be used in your agent flow or automation.

Generate invoice document using the prompt

Generate invoice document using the prompt dynamically
Generate invoice document using the prompt dynamically

Click on the “Save” button.

Step 6: Develop an Agent Flow to Generate Documents Dynamically

The next step is to create an agent flow where you will call the custom invoice document generation prompt and store the generated file in SharePoint as both Microsoft Word and PDF formats.

Below are my complete word invoice generation agent flow actions:

Copilot Studio Document Generation - Create Invoice Word File
Copilot Studio Document Generation – Create Invoice Word File

Document Generation Agent Flow: Action Explanation and Configuration

When an agent calls this flow trigger:

For the “When an agent calls this flow” trigger, you need to configure two text inputs:

  • User Input and
  • Invoice Number
When an agent calls this flow trigger - configuration
When an agent calls this flow trigger – configuration

Run a Prompt configuration:

For the “Run a Prompt” action, select the prompt you created for document generation. You need to pass two input parameters: Invoice Number and User Input.

For the Invoice Number, use the formula as shown below. For the User Input, pass the value from the “When an agent calls this flow” trigger.

Run a prompt configuration in Copilot Studio agent
Run a prompt configuration in Copilot Studio agent

Invoice Number Formula:

concat('INV-', utcNow('yyyyMMdd-HHmmss'))

Create File – Generate Word File:

For the “Create file” action, provide your SharePoint Online site URL and the folder path from your document library where you want to store the generated invoice document.

For the file name, use the formula as shown below. For the file content, select “Document Output Content Bytes” from the “Run a Prompt” action.

Create file - Document generation in Copilot Studio agent
Create file – Document generation in Copilot Studio agent

File Name formula:

concat('Invoice_',utcNow(),'.docx')

The above “Create file” action will generate the invoice file in the SharePoint document library as a Word file (.docx).

Convert Word Document to PDF

This “Convert Word Document to PDF” action converts the generated Word invoice file into a PDF and stores it in the SharePoint document library.

For the Location parameter, select your SharePoint site. For the Document Library, choose the library where you want to save the converted invoice PDF file. For the File parameter, pass “body/name” from the output of the “Create file” action.

Convert Word document to PDF
Convert Word document to PDF

Create File – Save the Invoice PDF in SharePoint:

Next, add another “Create file” action. This action will save the PDF version of the generated Word invoice file in the SharePoint document library.

For this, configure the following parameters:

  • Site Address: Provide your SharePoint site URL
  • Folder Path: Select the folder path from your document library where you want to store the invoice PDF file
  • File Name: Use the formula shown below
  • File Content: Pass the body output (PDF document) from the “Convert Word Document to PDF” action
Convert word document to PDF in SharePoint
Convert word document to PDF in SharePoint

File Name:

concat('Invoice_',utcNow(),'.pdf')

Respond to the Agent

Finally, in the “Respond to the agent” action, create a File Link output (text) variable. Add the formula below to construct the PDF invoice document link, which will be returned to the end user.

Respond to the agent configuration
Respond to the agent configuration

File link formula:

concat(

    'https://ztncx.sharepoint.com/sites/DemoSite',

    replace(body('Create_file_PDF')?['Path'], '​', '%20')

)

That’s it—we’re done with the agent flow development. Now, save and publish the flow.

Next, add this agent flow as a tool so it can be automatically triggered based on user input.

Basically, your agent will have the below two tools:

  • Generate invoice prompt
  • Generate invoice agent flow
Generate document in Copilot Studio tool
Generate document in Copilot Studio tool

Watch Demo: Copilot Studio Document Generation (Word & PDF) – Full Tutorial

Summary

In this guide, you learned how to perform Copilot Studio document generation to create dynamic Word and PDF documents from a template. By using structured placeholders in a Word template and combining them with a prompt in Copilot Studio, you can automatically generate invoices based on user input.

The process includes creating a prompt, configuring an agent flow, saving the generated file to SharePoint, and returning it as a downloadable document. You also saw how to convert the Word file into PDF for final sharing. This approach helps streamline document automation, reduce manual effort, and ensure consistency across all generated invoices.

See Also

About Post Author


Discover more from Global SharePoint

Subscribe to get the latest posts sent to your email.

Do you have a better solution or question on this topic? Please leave a comment