If you use InDesign Data Merge, you’ve probably felt the pain: you merge a CSV, get a single multi-page document, and then you still have to export every page as its own JPG and PDF—and name each file correctly. This post introduces a simple script that automates the whole job.
What this script does
- Exports one JPG and one PDF per record (one record = one page)
- Names each file from text on the page (a labeled text frame)
- Skips numbering unless a duplicate filename exists
- Works across different InDesign versions (tries both merge methods and falls back to the current doc if needed)
- Creates tidy JPG and PDF subfolders automatically
Why it’s useful
- Batch export hundreds or thousands of records in minutes
- Filenames reflect real data (SKU, customer name, order ID, etc.)
- Clean deliverables for review and print
- Fewer manual steps and fewer mistakes
- Fits many workflows: labels, certificates, tickets, menus, product sheets, one-sheets
Typical use cases
- Retail and e-commerce: product sheets named by SKU
- Events and education: badges or certificates named by person
- Manufacturing and logistics: spec sheets named by part or lot
- Agencies and in-house teams: regional flyers or dealer sheets named by territory
How it works (simple steps)
- Prepare your Data Merge
- Link your CSV/TXT in the Data Merge panel
- Place the field you want to use for filenames on the page
- Label the filename frame
- Window → Utilities → Script Label
- Select the text frame that holds your filename text
- Set its label to
export_name
- Run the script
- Put the JSX in your Scripts panel
- Open your document and run it
- Choose an output folder
- The script will merge (or use your merged doc), then export each page as JPG and PDF with clean filenames
- Collect your files
- Look in the JPG and PDF folders the script creates
What makes this script different
- Cross-version merge support (works even if your build uses a different merge function)
- Duplicate-only suffixing (no number added unless a name already exists)
- Robust filename cleaning (removes illegal characters and odd whitespace)
- Practical defaults (300 dpi JPGs, single-page PDFs, organized output folders)
- Clear code that teams can adjust
Compatibility and requirements
- Adobe InDesign on macOS or Windows (tested on current builds, including 2025)
- A Data Merge document linked to a CSV/TXT, or a document already merged
- One labeled text frame per record/page with the label
export_name
Pro tips
- Only need PDFs or only JPGs? Comment out the other export block.
- Want a specific PDF preset? Set it in the script once and forget it.
- Prefer a different duplicate style (dash, parentheses, timestamp)? It’s a one-line change.
- Need multiple data points in the filename? Compose them in the labeled frame (for example,
{{FirstName}} {{LastName}} - {{OrderID}}
).
Quick troubleshooting
- “Expected: )” error: usually caused by smart quotes or editing a regex line. Use the distributed file as is.
- “createMergedDocument is not a function”: your build may expose a different method. The script already tries both and will export the current document if needed.
- Blank filenames: confirm the frame is labeled
export_name
and contains text after merge.
Get the script
You’ll receive:
- The production-ready JSX
- A quick-start PDF with screenshots
- Lifetime updates for compatibility tweaks
- Priority email support
Ready to automate your Data Merge exports?
Turn a tedious, error-prone task into a one-click workflow.