Fill DOCX Templates

Fill Word Templates via API

Create .docx templates with {placeholder} tags in Microsoft Word. Send JSON data via API. Get filled documents back with all formatting preserved.

How it works

Three steps to a filled Word document

Create your template in Word, upload it once, then fill it with different data as many times as you need.

1

Create your .docx template

Open Word and add {placeholder} tags where you want data inserted. Use {#loop}...{/loop} for repeating sections and {%image} for images.

2

Upload and send data

Upload your template via API or dashboard. Then POST your JSON data — each key maps to a {placeholder} tag in the document.

3

Download filled document

Get a signed download URL for the filled .docx. All formatting, styles, headers, and footers from the original template are preserved.

Integration

Fill a contract template

Map your {tags} to JSON keys. Arrays create loops for table rows. Images are inserted from base64 data.

curl -X POST https://api.pdfforge.dev/v1/documents/fill \
  -H "Authorization: Bearer pk_live_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "template_id": "tpl_contract",
    "data": {
      "client_name": "Acme Corp",
      "contract_date": "2026-02-26",
      "items": [
        { "service": "API Integration", "price": "$5,000" },
        { "service": "Support Plan", "price": "$1,200/yr" }
      ]
    }
  }'

Benefits

Why developers choose PDFForge for DOCX templates

Simple tag syntax that non-developers can use. Full formatting preservation. Editable output.

Simple tag syntax

Just type {client_name} in your Word document. No special plugins or markup language — anyone who can use Word can create templates.

Image insertion

Insert images dynamically with {%logo}. Pass base64-encoded image data in your JSON. The image is placed exactly where the tag is in the document.

Loops and conditionals

Use {#items}...{/items} to repeat rows in a table or paragraphs. Use {#variable}...{/variable} to show content when a value is truthy, hidden when falsy.

Preserves all formatting

Fonts, colors, styles, headers, footers, page breaks — everything in your Word template is preserved. The filled document looks exactly like the original.

Editable output

The output is a standard .docx file that can be opened and edited in Word, Google Docs, or LibreOffice. Perfect for documents that need manual review or signatures.

Table support

Loop over rows in tables to generate dynamic line items, invoice rows, or report data. Table formatting and column widths are preserved.

Comparison

PDFForge vs. alternatives

Without PDFForge
With PDFForge
Manual mail merge in Word — click-heavy, error-prone
One API call with JSON data — fully automated
Server-side Office (COM automation) — licensing, crashes, scaling issues
No Office installation needed — lightweight and fast
Custom Python (python-docx) — build merge logic from scratch
Simple {tag} syntax, loops, conditionals, and images built-in
Re-create documents from scratch in code
Reuse existing Word templates — non-developers can update them
Different output across Word versions and OS
Consistent output — same engine, same result every time
Manage file storage, cleanup, and access control
Built-in cloud storage with signed URLs and retention policies

FAQ

Frequently asked questions

PDFForge uses curly brace syntax: {variable_name} for simple values, {#section}...{/section} for loops and conditionals, and {%image_tag} for images. Tags are case-sensitive and must match exactly between your template and JSON data.

Yes. Use {%tag_name} in your template where you want the image. In your JSON, provide base64-encoded image data. Images are inserted at a default size. Custom image dimensions are not yet configurable via the API.

Yes — fonts, colors, bold, italic, headers, footers, page numbers, tables, and all other Word formatting is preserved exactly. The tag is replaced with your data, but the surrounding formatting remains unchanged.

Yes. Place {#items} before the first row you want to repeat and {/items} after the last row. Each row will be duplicated for each item in your array. Column widths and cell formatting are preserved.

PDFForge returns a .docx file. If you need PDF output, consider using the HTML-to-PDF feature instead, which gives you pixel-perfect PDF output from HTML templates. Alternatively, you can use a separate conversion service on the .docx output.

Templates can be up to 32 MB. Most Word documents are well under 5 MB. If your template contains many embedded images, consider keeping them small or removing them from the template and inserting them dynamically via the {%image} tag with base64 data.

Absolutely. That is one of the biggest advantages of DOCX templates. Anyone who knows Microsoft Word can create or update templates by typing {tags} in the right places. No coding required for template changes.

Yes. Use {#show_discount}...{/show_discount} to conditionally include a section — the block is shown when the value is truthy and hidden when falsy. Nested sections and loops are supported. Missing tags are silently replaced with empty strings.

Ready to generate your first document?

Start free with 50 documents per month. No credit card required. Up and running in under 5 minutes.