Skip to content
Text to PDF

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 (tectonic or texlive).
  • 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

MethodEffortStrengthWatch out for
Browser converterDrop files, downloadNo install, no upload, batchNo custom headers/footers
Command line (cat + enscript)One commandScriptable, handles hundredsRequires install, plain output
Python scriptWrite once, reuseFull control, automatableSetup overhead for a one-off
Word processorCopy-paste or insertFull formatting after mergeManual, 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.

Questions about merging text files into PDF

Can I control the order the files appear in the merged PDF?

Yes. Most tools let you reorder files before merging. A browser converter typically shows a list you can drag into the right sequence; a command-line tool processes files in the order you pass them on the command line.

Is there a limit to how many text files I can merge?

Server-based tools often cap uploads at 5–10 files or a total size. A client-side converter like Text to PDF has no upload limit because nothing leaves your machine — the practical ceiling is your browser's available memory, which handles dozens of files comfortably.

Will the merged PDF be searchable, or does merging flatten the text?

If the source files are real text (not scanned images), the merged PDF is fully searchable and selectable. Merging plain text into a PDF does not flatten anything — every character stays in the text layer.

Can I merge .csv, .log, and .md files together with .txt files?

Yes. Any plain-text format works. The converter reads them all as text, so a .csv, a .log and a .txt can all go into the same merged PDF. Formatting differences between file types show up as-is — CSV commas stay, Markdown markers stay.

Does each file start on a new page, or do they flow together?

That depends on the tool. A batch converter that treats each file as a separate document will start each on its own page. Some tools also let you choose: separate pages or continuous flow. Check the merge option before you click download.

Keep reading