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:
- A PDF template uploaded to Mergram
- A CSV or TSV file with your data (comma, semicolon, or tab-separated)
- A Mergram account
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:
| Format | Delimiter | Extension | Common In |
|---|---|---|---|
| Comma-separated | , (comma) | .csv | US/UK exports, most CRM systems |
| Semicolon-separated | ; (semicolon) | .csv | European exports (where comma is decimal separator) |
| Tab-separated | \t (tab) | .tsv / .csv | Database 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
| Feature | CSV | Excel (.xlsx) | Google Sheets |
|---|---|---|---|
| Max rows | Up to 100,000 | Up to 100,000 | Up to 100,000 |
| Formulas | No | Yes | Yes |
| Multiple sheets | No | Yes | Yes |
| Auto-refresh | No | No | Yes (live connection) |
| Delimiters | Auto-detected | N/A | N/A |
| Best for | Database exports, CRM exports, simple data | Calculated fields, multi-sheet data | Live data, collaborative editing |
| Export from | Any system | Excel, Google Sheets | Google 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:
- Column headers in the first row (these become your merge field names)
- One data row per document (each row generates one merged PDF)
- 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:
| Situation | Example | CSV Encoding |
|---|---|---|
| Value contains comma | Acme Corp, Inc. | "Acme Corp, Inc." |
| Value contains quotes | He said "hello" | "He said ""hello""" |
| Value contains line break | Multi-line address | "Line 1\nLine 2" |
| Value is empty | Missing 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 Type | Example | Works with UTF-8 |
|---|---|---|
| Accented Latin | cafe, uber, nandu | Yes |
| Vietnamese tones | Tai, Tieng Viet | Yes |
| Chinese | New Documents | Yes |
| Japanese | New Documents | Yes |
| Korean | New Documents | Yes |
| Cyrillic | Moscow | Yes |
| Arabic | New Documents | Yes |
Fixing Encoding Issues
If you see garbled characters (mojibake) in your merged PDFs:
- Re-save the CSV with UTF-8 encoding — In Excel: Save As → CSV → Tools → Web Options → Encoding → UTF-8
- Check the BOM — Some systems need a UTF-8 BOM (Byte Order Mark) at the start of the file
- 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
- Navigate to a report or list view
- Click Printable View or Export Details
- Select CSV Export
- The file downloads with all visible columns
HubSpot
- Go to your contacts, deals, or custom object list
- Click Export in the top-right
- Choose CSV format
- 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
- Open your data in Excel
- Go to File → Save As
- Choose CSV (Comma delimited) (*.csv)
- Select UTF-8 encoding if available (Excel 2016+)
- Save and upload to Mergram
Common CSV Pitfalls
| Issue | Cause | Fix |
|---|---|---|
| Columns misaligned | Inconsistent number of delimiters per row | Check for unquoted values containing the delimiter |
| Garbled characters | Non-UTF-8 encoding (e.g., Windows-1252) | Re-save with UTF-8 encoding |
| Missing data | Empty cells not properly represented | Ensure empty values are just , , not skipped |
| Wrong delimiter detected | Very short files with few rows | Try saving as .xlsx instead, or add more sample rows |
| Extra whitespace | Spaces around values | Trim spaces in your source data or use a header row |
Best Practices for CSV Data
- Use descriptive column headers — Names like
FirstNameandLastNameare better thancol1andcol2 - Remove empty trailing rows — Some exports include blank rows at the end; delete them
- Standardize date formats — Pick one format (ISO 8601: YYYY-MM-DD) and use it consistently
- Validate email addresses — If using email campaigns, check that email columns contain valid addresses
- Keep a backup — Save a copy of your original CSV before making edits
- 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.