Skip to content

How to Mail Merge PDFs from CSV Files

Use CSV or TSV files as your data source for PDF mail merge. Import comma-separated, semicolon-separated, or tab-separated data for personalized documents.

Mail Merging PDFs from CSV and TSV Files

Excel and Google Sheets are common data sources, but many business systems — CRMs, databases, ERPs — export data as CSV files. Mergram accepts CSV and TSV files directly, with automatic delimiter detection and full Unicode support. This guide covers everything you need to know about using CSV as your merge data source.

Prerequisites

To merge PDFs from a CSV file, you need:

CSV is the universal data format

CSV (Comma-Separated Values) is the most widely supported data export format. Nearly every database, CRM, ERP, and business application can export to CSV. If your system exports data, it almost certainly supports CSV — making it the most reliable way to get data into Mergram.

Supported CSV Formats

Mergram auto-detects the delimiter in your file, so you don’t need to configure anything:

FormatDelimiterExtensionCommon In
Comma-separated, (comma).csvUS/UK exports, most CRM systems
Semicolon-separated; (semicolon).csvEuropean exports (where comma is decimal separator)
Tab-separated\t (tab).tsv / .csvDatabase exports, Google Sheets downloads

All three formats are processed identically. The first row is treated as column headers and every subsequent row as data.

Comparing Data Source Options

FeatureCSVExcel (.xlsx)Google Sheets
Max rowsUp to 100,000Up to 100,000Up to 100,000
FormulasNoYesYes
Multiple sheetsNoYesYes
Auto-refreshNoNoYes (live connection)
DelimitersAuto-detectedN/AN/A
Best forDatabase exports, CRM exports, simple dataCalculated fields, multi-sheet dataLive data, collaborative editing
Export fromAny systemExcel, Google SheetsGoogle Sheets

Use Google Sheets for live data

If your data changes frequently, consider using Google Sheets instead of CSV. Mergram can connect directly to Google Sheets and pull the latest data at merge time — no need to re-upload a file each time. See the Google Sheets guide for setup instructions.

Preparing Your CSV File

Basic Structure

A well-formed CSV file has:

  1. Column headers in the first row (these become your merge field names)
  2. One data row per document (each row generates one merged PDF)
  3. Consistent column count across all rows

Example CSV content:

Name,Email,Company,Amount,DueDate
Alice Chen,alice@acme.com,Acme Corp,$1250.00,2025-02-28
Bob Martinez,bob@globex.com,Globex Inc,$3400.00,2025-02-28
Carol Johnson,carol@initech.com,Initech,$890.00,2025-03-15

Handling Special Characters in CSV

CSV files use quoting rules to handle values that contain the delimiter character, line breaks, or the quote character itself:

SituationExampleCSV Encoding
Value contains commaAcme Corp, Inc."Acme Corp, Inc."
Value contains quotesHe said "hello""He said ""hello"""
Value contains line breakMulti-line address"Line 1\nLine 2"
Value is emptyMissing data, (empty between delimiters)

Most export tools handle quoting automatically. If you’re creating CSV files manually, wrap any field containing commas, quotes, or line breaks in double quotes.


Encoding and International Characters

UTF-8 Encoding

For reliable handling of international characters, always save your CSV with UTF-8 encoding:

Character TypeExampleWorks with UTF-8
Accented Latincafe, uber, nanduYes
Vietnamese tonesTai, Tieng VietYes
ChineseNew DocumentsYes
JapaneseNew DocumentsYes
KoreanNew DocumentsYes
CyrillicMoscowYes
ArabicNew DocumentsYes

Fixing Encoding Issues

If you see garbled characters (mojibake) in your merged PDFs:

  1. Re-save the CSV with UTF-8 encoding — In Excel: Save As → CSV → Tools → Web Options → Encoding → UTF-8
  2. Check the BOM — Some systems need a UTF-8 BOM (Byte Order Mark) at the start of the file
  3. Use a text editor — Open the CSV in a code editor (VS Code, Notepad++) and re-save with UTF-8 encoding

Export from Google Sheets for clean UTF-8

Google Sheets exports clean UTF-8 CSV files. If you’re having encoding issues with Excel-exported CSV, open the file in Google Sheets and re-download as CSV. This reliably fixes encoding problems.

Exporting CSV from Common Systems

Salesforce

  1. Navigate to a report or list view
  2. Click Printable View or Export Details
  3. Select CSV Export
  4. The file downloads with all visible columns

HubSpot

  1. Go to your contacts, deals, or custom object list
  2. Click Export in the top-right
  3. Choose CSV format
  4. Download the exported file from the notifications panel

MySQL / PostgreSQL

-- MySQL
SELECT name, email, company, amount
INTO OUTFILE '/tmp/merge_data.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM invoices
WHERE status = 'pending';

-- PostgreSQL
COPY (SELECT name, email, company, amount FROM invoices WHERE status = 'pending')
TO '/tmp/merge_data.csv' WITH CSV HEADER;

Microsoft Excel

  1. Open your data in Excel
  2. Go to File → Save As
  3. Choose CSV (Comma delimited) (*.csv)
  4. Select UTF-8 encoding if available (Excel 2016+)
  5. Save and upload to Mergram

Common CSV Pitfalls

IssueCauseFix
Columns misalignedInconsistent number of delimiters per rowCheck for unquoted values containing the delimiter
Garbled charactersNon-UTF-8 encoding (e.g., Windows-1252)Re-save with UTF-8 encoding
Missing dataEmpty cells not properly representedEnsure empty values are just , , not skipped
Wrong delimiter detectedVery short files with few rowsTry saving as .xlsx instead, or add more sample rows
Extra whitespaceSpaces around valuesTrim spaces in your source data or use a header row

Best Practices for CSV Data

  1. Use descriptive column headers — Names like FirstName and LastName are better than col1 and col2
  2. Remove empty trailing rows — Some exports include blank rows at the end; delete them
  3. Standardize date formats — Pick one format (ISO 8601: YYYY-MM-DD) and use it consistently
  4. Validate email addresses — If using email campaigns, check that email columns contain valid addresses
  5. Keep a backup — Save a copy of your original CSV before making edits
  6. Use .xlsx for complex data — If your data needs formulas or multiple sheets, switch to Excel format

Common Issues and Troubleshooting

File not recognized as CSV: Ensure the file extension is .csv, .tsv, or .txt. All three extensions are supported natively — no renaming required. Mergram detects the format by extension and auto-detects the delimiter.

Only one column detected: The delimiter isn’t being recognized. This usually happens with semicolon-delimited files that have very few rows. Try opening the file in a text editor to verify the delimiter, then re-save with comma separation.

Headers have extra spaces: Column names with leading or trailing spaces (e.g., Name instead of Name) create fields that are harder to map. Trim whitespace in your column headers before uploading.

Large CSV files are slow to upload: CSV files with tens of thousands of rows may take a moment to parse. The upload processes server-side — you can start configuring your template while the data loads.

Line breaks within fields: If a CSV value contains actual line breaks (common in address fields or notes), ensure the value is wrapped in double quotes. Unquoted line breaks cause Mergram to treat each line as a separate row.

Get Started

Export your data as CSV, upload it with your PDF template to the Mergram editor, and start generating personalized documents. The auto-detection handles delimiter and encoding — just upload and merge.

Step-by-step guide

  1. 1

    Export or Create CSV

    Export data from your CRM, database, or create a CSV file manually. Ensure headers are in the first row and encoding is UTF-8.

  2. 2

    Upload CSV

    Upload your CSV file to Mergram along with your PDF template. Mergram auto-detects the delimiter and encoding.

  3. 3

    Map Fields

    Column headers from your CSV appear as available fields. Drag them onto the canvas to create mapped text fields.

  4. 4

    Merge

    Preview with real data, then run the merge to generate personalized PDFs.

Frequently asked questions

What delimiter formats does Mergram support?
Mergram auto-detects comma-separated, semicolon-separated, and tab-separated values. You don't need to specify the delimiter — upload your file and Mergram handles the detection automatically.
Can I use CSV files exported from my CRM or database?
Yes. Most CRM systems (Salesforce, HubSpot, Pipedrive) and databases export data as CSV. Download the CSV from your system and upload it directly to Mergram.
What character encoding should my CSV use?
UTF-8 encoding is strongly recommended. It preserves accented characters, CJK text, Cyrillic, and other non-ASCII content. Most modern applications export CSV in UTF-8 by default.
Is there a difference between using CSV and Excel files?
Functionally, no — both work identically in Mergram. CSV is simpler and more universal (exported by every database and CRM). Excel supports formulas, multiple sheets, and richer formatting. Use whichever format your data source provides.
Can CSV files handle international characters?
Yes, as long as the file is saved with UTF-8 encoding. Names with accents, CJK characters, Arabic text, and other Unicode content are fully supported. If you see garbled characters, re-save the CSV with UTF-8 encoding.

Ready to try it yourself?

Start merging PDFs in minutes — free account required, no credit card needed.

Related articles