Skip to main content
Post

Fill and Sign a Word Document with Power Apps and Power Automate, without Premium Actions, from Paulie M

How to fill placeholders in a Word document template from Power Automate without the premium Word connector, by treating the .docx file as a ZIP archive and editing its internal XML directly.

Fill and Sign a Word Document with Power Apps and Power Automate, without Premium Actions, from Paulie M

TL;DR: Save your Word template as a Word XML Document (*.xml), a single-file format that keeps text and images as plain XML. A Power Apps form sends the field values and the Pen input signature to a flow, the flow swaps the placeholders with replace() and writes the filled file back with Create file. Standard connectors only.

A .docx file is a ZIP archive full of XML. Paulie M uses the fact that Word documents are XML under the hood to fill and sign a Word template from Power Apps and Power Automate without the premium Word connector.

💡 Challenge

You want a Power Apps form to produce a filled Word document with the user’s signature in it. The obvious action, Populate a Microsoft Word template, belongs to the Word Online (Business) connector, which is premium in Power Automate. Unzipping the .docx with Extract archive to folder works, but there is no standard action that zips the edited files back into a .docx.

✅ Solution

Work with the Word XML Document format (Office Open XML in a single flat file). Word stores every part of the document in one XML file, including images as base64 text. A flow can read that file as text, replace placeholder strings with real values, replace the base64 of a placeholder image with the base64 of the drawn signature, and save the result as one new file.

🔧 How It’s Done

1. Prepare the template in Word desktop.

🔸 Type a unique placeholder for each field, for example and. Type each placeholder in one go without changing the formatting inside it, so Word keeps it in one text run.

🔸 Insert a small PNG as the signature placeholder and size it the way the signature should appear. Keep it the only image in the document, so it is stored as /word/media/image1.png.

🔸 File > Save As > Word XML Document (*.xml) and upload the file to OneDrive for Business or a SharePoint library.

2. Capture the signature in Power Apps.

🔸 Add a Pen input control (PenInput1) and a button. JSON() with JSONFormat.IncludeBinaryData returns the drawing as a quoted data URI ("data:image/png;base64,..."), so strip the quotes before sending it:

1
2
3
4
5
FillAndSign.Run(
    txtCustomerName.Text,
    Text(dpOrderDate.SelectedDate, "dd.mm.yyyy"),
    Substitute(JSON(PenInput1.Image, JSONFormat.IncludeBinaryData), """", "")
)

3. Build the flow.

🔸 Trigger: When Power Apps calls a flow (V2) with three text inputs: CustomerName, OrderDate, Signature.

🔸 Get file content using path (OneDrive for Business) on the template, with Infer Content Type set to No, so the body always arrives as base64 in $content.

🔸 Compose TemplateText:

1
base64ToString(body('Get_file_content_using_path')?['$content'])

🔸 Compose FilledText for the text placeholders:

1
replace(replace(outputs('TemplateText'), '', triggerBody()?['text']), '', triggerBody()?['text_1'])

4. Swap the placeholder image for the signature.

🔸 The image part looks like <pkg:part pkg:name="/word/media/image1.png" ...><pkg:binaryData>BASE64</pkg:binaryData></pkg:part>. Split the text at the part name and rebuild it with the signature’s base64 in the middle:

🔸 Compose Head: first(split(outputs('FilledText'), 'pkg:name="/word/media/image1.png"'))

🔸 Compose Tail: last(split(outputs('FilledText'), 'pkg:name="/word/media/image1.png"'))

🔸 Compose SignedText:

1
2
3
4
5
6
7
concat(
  outputs('Head'),
  'pkg:name="/word/media/image1.png"',
  slice(outputs('Tail'), 0, add(indexOf(outputs('Tail'), '<pkg:binaryData>'), 16)),
  last(split(triggerBody()?['text_2'], ',')),
  slice(outputs('Tail'), indexOf(outputs('Tail'), '</pkg:binaryData>'))
)

🔸 last(split(..., ',')) drops the data:image/png;base64, prefix, 16 is the length of <pkg:binaryData>.

5. Save the filled document.

🔸 Create file (OneDrive for Business or SharePoint) with a name like Order-@{triggerBody()?['text']}.xml and outputs('SignedText') as file content. Word desktop opens it as a normal document, and Save As .docx turns it into a regular Word file.

🎉 Result

A Power Apps form produces a filled Word document with the drawn signature in place, built with the Power Apps trigger, the OneDrive for Business connector and expressions only.

🌟 Key Advantages

🔸 No premium connector: OneDrive for Business and SharePoint are standard connectors.

🔸 Formatting stays in Word: fonts, tables and layout come from the template, the flow only swaps text.

🔸 Signature included: the Pen input image lands exactly where the placeholder image was, at the same size.

⚠️ Good to Know

🔸 Split placeholders: if Word splits a placeholder into several runs (spell check marks, formatting changes), replace() finds nothing. Retype the placeholder in one go, or check the XML for the exact string.

🔸 Escape special characters: values containing & or < must be written as &amp; and &lt;, otherwise the XML is invalid and Word refuses to open the file. Wrap each value in replace(replace(value, '&', '&amp;'), '<', '&lt;').

🔸 PDF output: the OneDrive Convert file action does not accept .xml as a source, and Convert Word Document to PDF is premium. If you need a PDF with standard actions only, build the document as HTML and convert that instead (see Tip 92 below).

🎥 Video Tutorial

🛠️ FAQ

1. Why does this avoid the premium Word connector?

The Word Online (Business) connector, which contains “Populate a Microsoft Word template”, is a premium connector in Power Automate. Reading the template, replacing text with replace() and writing the result back only needs the standard OneDrive for Business (or SharePoint) connector and built-in expressions.

2. Why use the Word XML Document format instead of the .docx file?

A .docx is a ZIP archive. Power Automate has a standard action to extract an archive (Extract archive to folder), but no standard action that creates one, so you cannot re-pack an edited .docx. The Word XML Document format stores the whole document, images included, in one plain XML file that a flow can edit and save as a single file.

3. What does “sign” mean here - a real digital signature?

No. It’s a visual signature: the image drawn in a Power Apps Pen input control is placed into the document. It’s not a cryptographic e-signature with a legal audit trail.

4. Can I convert the result to PDF without premium?

Not from the XML file directly. The OneDrive Convert file action supports doc, docx, htm, html and other formats as a PDF source, but not xml. Convert Word Document to PDF is part of the premium Word Online (Business) connector.

🔸 #PowerPlatformTip 94: ‘Extract Text from DOCX’ - the reverse operation, reading a Word file’s internal XML instead of writing to it.

🔸 #PowerPlatformTip 92: ‘Free PDF Tools in PowerAutomate’ - create PDFs from HTML with standard actions.


You can see this video here on my blog because I have rated this video with 5 stars in my YouTube video library. This video was automatically posted using PowerAutomate.

This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy, which runs free live workshops (in German). See the next free workshop dates (in German). For companies that want this implemented for them, see KMUpower: Power Platform consulting & automation for SMEs (DACH).

This post is licensed under CC BY 4.0 by the author.

Microsoft and the Power Platform product names (for example Power Apps, Power Automate, Copilot Studio) are trademarks of the Microsoft group of companies. This is an independent website. It is not operated, sponsored or endorsed by Microsoft.