Replace Text With Image In Word in n8n
Replace Text With Image In Word is a PDF4me node action in n8n that finds a text marker inside a .docx and puts an image in its place. Use it to drop a signature into a contract, a logo into a branded template, or a generated QR code into a shipping document, without any manual editing.
What this node does
This action takes two independent inputs: a Word document and an image, each with its own input-type dropdown. It searches the document for the exact string in Search Text and substitutes the image wherever that string appears on the pages you scope. The result is a new .docx with the picture embedded, ready for the next node.
Authenticating Your API Request
Every PDF4me node in n8n requires a valid Credential to connect with. Create or select one that holds your PDF4me API key so the workflow can authenticate document requests.
Important Facts You Should Not Miss
replacementsMade rather than on success.Word mail merge vs Replace Text With Image: which should I use?
Word's native mail merge is built to substitute text. Placing a picture normally means nesting an INCLUDEPICTURE field inside a MERGEFIELD, pointing it at a stable file path, and refreshing fields before the images appear. That is workable on a desktop and awkward inside an automated pipeline. This node treats the placeholder as ordinary document text and swaps a real image in, so the file that leaves the workflow already has the picture embedded.
| Word mail merge with INCLUDEPICTURE | PDF4me Replace Text With Image | |
|---|---|---|
| Image source | A file path the field can reach | Binary data, base64, or a URL |
| Field refresh | Often needed before pictures render | Not applicable, the image is embedded |
| Runs unattended | Fragile outside the desktop app | Designed for it |
| Per-page targeting | Not built in | Page Numbers plus first-page skip |
| Several markers | One merge pass | Chain one node per marker |
| Which vs which | Pick for desktop, one-off merges | Pick for unattended workflow runs |
How do I set up the node?
Add the PDF4me Replace Text With Image In Word action to your n8n workflow. For first-time setup, see the n8n Integration Guide.
Prerequisites: a PDF4me API credential, an n8n workflow, a .docx containing your marker text, and the image to insert.

What are the parameters?
Fields appear in the panel in the order below. Only Search Text is flagged as mandatory; the rest carry defaults or depend on which input mode you choose.
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
| Word Document Input Type | Options | Required | How the .docx reaches the node: Binary Data, Base64 String, or URL. The matching source field appears directly beneath it. | Binary Data |
| Word Document Binary Property | String | Conditional | Name of the binary property holding the Word file. Shown when the input type is Binary Data. | data |
| Base64 Word Document Content | String | Conditional | The .docx as a base64 string. Shown when the input type is Base64 String. | UEsDBBQABgAI... |
| Word Document URL | String | Conditional | A publicly reachable link to the .docx. Shown when the input type is URL. | https://example.com/contract.docx |
| Word Document Name | String | Optional | Filename used for the document being processed. Ships with a placeholder default. | document.docx |
| Image Input Type | Options | Required | How the image reaches the node. This is a separate dropdown from the Word document and is set independently. | Binary Data |
| Image Binary Property | String | Conditional | Name of the binary property holding the image. Shown when the image input type is Binary Data. | data |
| Base64 Image Content | String | Conditional | The image as a base64 string. Shown when the image input type is Base64 String. | iVBORw0KGgoAAAANS... |
| Image URL | String | Conditional | A publicly reachable link to the image. Shown when the image input type is URL. | https://example.com/logo.png |
| Image File Name | String | Optional | Filename of the image being inserted. Ships with a placeholder default. | image.png |
| Is First Page Skip | Toggle | Optional | Excludes page one from the search. Ships switched off. Useful when a cover page or letterhead must stay untouched. | off |
| Page Numbers | String | Optional | Pages to search. Accepts a single page, a comma list, or a hyphenated range. Ships with 1. | 1 |
| Search Text | String | Required | The exact marker string to find and replace. The node shows a validation warning while this is empty. | [LOGO_PLACEHOLDER] |
| Output Binary Field Name | String | Optional | Property name the resulting .docx is written to for the next node. Ships with data. | data |
The field accepts a single page (3), a comma-separated list (1,4,7), a hyphenated range (2-6), or a mix of the two (1,3,5-8). Scope it to the pages that really contain the marker so a stray match elsewhere in a long document does not pick up an image.
What does the node return?
| Field | Type | Description | Example |
|---|---|---|---|
| success | Boolean | Whether the operation completed. Note that a run which found no matches still returns true. | true |
| message | String | Human-readable status text, used for error detail when something fails. | Text replaced with image successfully |
| fileName | String | Filename of the generated Word document. | document_with_images.docx |
| mimeType | String | MIME type of the output, always the .docx type. | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
| fileSize | Number | Size of the generated document in bytes. | 125430 |
| docName | String | Document name reference, matching fileName. | document_with_images.docx |
| textReplacementCompleted | Boolean | Confirms the replacement pass ran to completion. | true |
| replacementsMade | Number | How many instances of the search text were substituted. This is the field to branch on. | 3 |
N8N Action Response
- JSON
- Binary
[
{
"success": true,
"message": "Text replaced with image successfully",
"fileName": "document_with_images.docx",
"mimeType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"fileSize": 125430,
"docName": "document_with_images.docx",
"textReplacementCompleted": true,
"replacementsMade": 3
}
]
data
─────────────────────────────
File Name: document_with_images.docx
File Extension: docx
Mime Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
File Size: 122.5 KB
Access the file in later nodes through $binary.data, using whatever name you set in Output Binary Field Name.
Typical Setups
Practical Tips
- Branch on
replacementsMade, notsuccess. A run that matches nothing still reports success. An IF node checking that the count is above zero catches a broken template before the document reaches a customer. - Type the marker once, then copy it. If part of a placeholder is retyped or restyled in Word, the program splits it into separate formatting runs internally and the search no longer sees one contiguous string, even though the page looks unchanged.
- Pick markers that cannot occur naturally. Bracketed uppercase tokens such as
[LOGO_PLACEHOLDER]will not collide with body copy the way a bare word likeLogocan. - Chain nodes for multiple images. Feed each node's output document into the next node's input to accumulate a logo, a signature, and a QR code in one file.
- Mind the placeholder's own formatting. The image lands where the text was, so a marker sitting in a centred, generously spaced paragraph generally produces a better result than one buried mid-sentence.
- Prefer URL mode for static artwork. A company logo that never changes does not need to travel through the workflow as binary data on every execution.
Cheat Sheet
| Goal | Setting |
|---|---|
| Insert a signature image | Search Text = your signature marker, image via Binary Data |
| Leave the cover page alone | Is First Page Skip on |
| Search only pages 2 to 5 | Page Numbers = 2-5 |
| Use a hosted logo | Image Input Type = URL, Image URL = the link |
| Detect a failed match | Check replacementsMade equals 0 |
| Feed the result onward | Read the property named in Output Binary Field Name |
Common Questions
Why does Word mail merge struggle with images?
Word's built-in mail merge substitutes text. Getting a picture in traditionally means an INCLUDEPICTURE field nested with a MERGEFIELD, which requires the images to sit at stable file paths and often needs a manual field refresh before they appear. This node takes a different route: it treats the placeholder as ordinary text in the .docx and swaps an actual image in its place, so the merged document arrives with the picture already embedded.
Do the Word document and the image have to use the same input method?
No. Word Document Input Type and Image Input Type are two separate dropdowns configured independently. A common pattern is Binary Data for the .docx coming from a previous n8n node, and URL for a logo that lives at a fixed address, which avoids fetching the same image on every run.
What happens if the search text is not found?
The action completes and returns a document, but nothing is substituted. Check replacementsMade in the response: a value of 0 means the marker never matched. The usual cause is Word having split the placeholder across internal formatting runs, which happens when part of the marker was retyped or restyled, so it no longer exists as one contiguous string even though it looks correct on screen.
Can one run replace several different placeholders?
One execution handles one Search Text value paired with one image. A template that needs a logo, a signature, and a QR code is handled by chaining three of these nodes, each feeding its output document into the next one's input, so the substitutions accumulate in a single file.
Which fields are actually required?
Search Text is the only field the node flags as mandatory. Word Document Name, Image File Name, Page Numbers, and Output Binary Field Name all ship with working defaults, and the two input-type dropdowns each require whichever source field matches the mode you picked.
How do I keep a cover page from being changed?
Turn on the Is First Page Skip toggle, which ships off. It excludes page one from the search, which is useful when a letterhead or title page happens to contain the same wording as the marker you are targeting elsewhere in the document.
Related Actions in n8n
Same Task on Other Platforms
Use Cases
Document branding and visual identity
Replace placeholder tokens with company logos or product images so every document a workflow produces carries consistent branding, without anyone opening Word.
Signatures and authentication marks
Drop signature images, stamps, or seals into contracts and approval forms at the point the workflow reaches them, keeping the signing step inside the automation.
Generated artwork per record
Insert QR codes, barcodes, or charts that were produced earlier in the same workflow, which is how a batch of shipping documents or personalised reports ends up individually illustrated.
Further Reading
- Microsoft: Field codes, IncludePicture field documents the
INCLUDEPICTUREapproach this action replaces. - n8n: Work with files and images explains how binary files move between nodes, which is what the input and output property names refer to.