Guide
How to merge text files into one PDF
· 5 min read
You have a folder of .txt files — server logs, interview transcripts, config dumps, chapter drafts — and you need them in one PDF, in the right order, without copying and pasting each one. Here are four ways to do it, from zero-install to fully scripted.
Why merging matters more than converting one at a time
Converting each text file to a separate PDF and then gluing the PDFs together with a merge tool works, but it doubles the steps and often doubles the file size. A direct text-to-one-PDF pipeline skips the intermediate files entirely: the tool reads every source file, lays them out in sequence, and writes a single PDF with a consistent font, margin and page size throughout.
The result is one document you can email, archive or print — not a zip of fifteen PDFs with fifteen slightly different page layouts.
Method 1: drop files into a browser converter
Open a batch text-file-to-PDF converter, drag your files in (up to 20 at once), reorder them if needed, and download a single merged PDF. No install, no account, no file-size cap.
A client-side converter does the work inside your browser. The files never leave your machine, so there is no upload wait and no privacy concern — useful when the text contains credentials, logs with IP addresses, or anything you would not drop into an upload form.
Supported formats typically include .txt, .text, .log, .md, .markdown, .csv and more. The converter treats them all as plain text, so a mix of .txt and .log files merges seamlessly.
Page breaks. Each file starts on its own page by default, so the merged PDF has clear separation between sources. If you want continuous flow instead, look for a “merge” or “append” option in the converter.
Method 2: command line
If the files are already on disk, a one-liner does the job. The idea: concatenate the files with cat, pipe them into a text-to-PostScript converter, then into a PostScript-to-PDF converter.
- cat + enscript + ps2pdf (Linux / macOS)
cat file1.txt file2.txt file3.txt | enscript -p - | ps2pdf - merged.pdf - pandoc (cross-platform)
pandoc file1.txt file2.txt file3.txt -o merged.pdf
Pandoc accepts multiple input files natively and outputs one PDF. It needs a LaTeX engine installed (tectonicortexlive). - Glob pattern
cat logs/*.txt | enscript -p - | ps2pdf - all-logs.pdf
Shell globbing lets you merge an entire directory without listing every file.
The order depends on how your shell expands the glob — usually alphabetical. To control it, list files explicitly or rename them with a numeric prefix (01-intro.txt, 02-body.txt).
Method 3: a short Python script
When merging is a recurring task — nightly log exports, report generation, archiving support tickets — a script you run once and forget is the right tool. Python with FPDF2 or ReportLab handles it in about twenty lines:
from fpdf import FPDF
from pathlib import Path
files = sorted(Path("logs").glob("*.txt"))
pdf = FPDF()
pdf.set_auto_page_break(auto=True, margin=25)
for f in files:
pdf.add_page()
pdf.set_font("Courier", size=10)
for line in f.read_text(encoding="utf-8").splitlines():
pdf.cell(0, 5, line, new_x="LMARGIN", new_y="NEXT")
pdf.output("merged.pdf")Each file gets its own page. Change the glob pattern, the font or the page size to match your use case. Wrap it in a cron job or a CI step and the merge runs itself.
Method 4: copy into a word processor
Open a blank document in Word, LibreOffice Writer or Google Docs. Paste or insert each text file in sequence, add a page break between them, style the result however you like, and export as PDF. This gives full control over fonts, headings, margins and page numbers — at the cost of doing every step by hand.
The trade-off is the same as for single-file conversion: a word processor reflows text to the page width, so whitespace-sensitive content (code, logs, aligned tables) will not survive intact. If the text needs to look exactly as written, use one of the other three methods.
Which method to pick
| Method | Effort | Strength | Watch out for |
|---|---|---|---|
| Browser converter | Drop files, download | No install, no upload, batch | No custom headers/footers |
| Command line (cat + enscript) | One command | Scriptable, handles hundreds | Requires install, plain output |
| Python script | Write once, reuse | Full control, automatable | Setup overhead for a one-off |
| Word processor | Copy-paste or insert | Full formatting after merge | Manual, reflows whitespace |
Tips for a clean merge
- Name files with a numeric prefix.
01-intro.txt,02-methods.txt— every tool sorts alphabetically by default, so a prefix guarantees the order you want. - Normalise encoding first. If some files are UTF-8 and others are Windows-1252, non-ASCII characters will garble at the boundary. Re-save everything as UTF-8 before merging.
- Decide on page breaks up front. One file per page keeps sources visually separate and makes the PDF easy to navigate. Continuous flow saves paper but blurs where one file ends and the next begins.
- Spot-check the last page. Merge tools occasionally drop trailing content from the final file if it lacks a newline at the end. Open the PDF, scroll to the bottom, and confirm nothing is missing.
Ready to merge? Drop your files, download one PDF
Text file to PDF accepts up to 20 files at once — drag them in, reorder, and download a single merged PDF. Free, no account, no watermark, and nothing leaves your browser.