Why Convert Plain Text to PDF?
Plain text files are the most universal document format in computing. Every operating system can open a .txt file, every programming language can read and write one, and they will remain readable decades from now. But plain text has fundamental limitations: no formatting, no pagination, no consistent appearance across systems, and no protection against editing.
PDF bridges every one of those gaps. When you convert TXT to PDF, you transform raw content into a polished, paginated, and portable document that looks identical on every device. Whether you are archiving server logs, publishing code documentation, distributing meeting notes, or submitting plain-text manuscripts, PDF gives your text a professional presentation layer.

This tutorial covers every approach to TXT-to-PDF conversion, from quick online tools to customized batch processing with full control over fonts, margins, headers, footers, and encoding.
Quick Conversion: Online Tools
The fastest way to convert a TXT file to PDF is with an online converter. No software installation, no command line, and no configuration required.
Using ConvertIntoMP4
- Navigate to our PDF converter
- Upload your
.txtfile (or drag and drop it) - Select PDF as the output format
- Click Convert
- Download your formatted PDF
Our converter automatically applies sensible defaults: a readable monospaced font, standard margins, and proper page breaks. For most use cases, this is all you need.
Pro Tip: For quick one-off conversions, online tools are the fastest path. But if you need consistent formatting across many files or want to customize fonts, margins, and headers, the methods below give you full control.
Online Conversion Considerations
| Factor | Online Conversion | Local Conversion |
|---|---|---|
| Speed | Instant (small files) | Setup required, then fast |
| Customization | Limited presets | Full control |
| Privacy | File uploaded to server | Stays on your machine |
| Batch support | Depends on tool | Full automation possible |
| Cost | Free for small files | Free (open-source tools) |
| Encoding handling | Automatic | Manual control available |
For sensitive documents like legal texts, financial records, or proprietary code, local conversion keeps your data private. Read our guide on data privacy in file conversion for a deeper look at this topic.
Method 1: Using Your Operating System
Every major operating system has built-in capabilities to convert text to PDF without installing additional software.
Windows: Print to PDF
- Open the
.txtfile in Notepad (or any text editor) - Press
Ctrl + Pto open the Print dialog - Select Microsoft Print to PDF as the printer
- Configure page settings (orientation, margins) if needed
- Click Print and choose a save location
This method uses your system's print subsystem, so the output matches exactly what you see on screen. The default font is typically Consolas or Courier New at 10pt.
macOS: Export to PDF
- Open the
.txtfile in TextEdit - Go to File > Print (or press
Cmd + P) - Click the PDF dropdown in the lower-left corner
- Select Save as PDF
- Add metadata (title, author, subject) in the dialog and save
macOS uses its Quartz rendering engine, producing clean, well-hinted PDF output. The default font in TextEdit is Helvetica for rich text or Monaco/Menlo for plain text mode.
Linux: Using lp or cups-pdf
On Linux, you can print to PDF from any application, or use the command line:
# Using cupsfilter (available on most Linux distributions)
cupsfilter input.txt > output.pdf
# Using enscript + ps2pdf (more control)
enscript -p output.ps input.txt
ps2pdf output.ps output.pdf
Method 2: Command-Line Conversion with Pandoc
Pandoc is the Swiss Army knife of document conversion. It reads dozens of input formats and produces high-quality output in dozens more.
Basic Conversion
pandoc input.txt -o output.pdf
That single command converts your text file to a PDF using LaTeX as the typesetting engine. The result is a professionally typeset document with proper paragraph spacing, page numbers, and margins.
Customizing Fonts and Margins
pandoc input.txt -o output.pdf \
--pdf-engine=xelatex \
-V geometry:margin=1in \
-V fontsize=11pt \
-V mainfont="IBM Plex Mono" \
-V monofont="JetBrains Mono"
The --pdf-engine=xelatex flag enables system font support, so you can use any font installed on your machine. The -V flags set LaTeX variables for margins, font size, and font families.

Adding Headers, Footers, and Page Numbers
Pandoc supports headers and footers through LaTeX's fancyhdr package:
pandoc input.txt -o output.pdf \
--pdf-engine=xelatex \
-V geometry:margin=1in \
-H header.tex
Create a header.tex file with your header/footer configuration:
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[L]{Document Title}
\fancyhead[R]{\today}
\fancyfoot[C]{\thepage}
\fancyfoot[R]{Confidential}
This adds the document title to the top-left, the date to the top-right, page numbers centered at the bottom, and a "Confidential" label at the bottom-right of every page.
Complete Formatting Options
| Option | Pandoc Flag | Example Value |
|---|---|---|
| Page margins | -V geometry:margin= | 1in, 2cm, 0.75in |
| Font size | -V fontsize= | 10pt, 11pt, 12pt |
| Main font | -V mainfont= | "Times New Roman" |
| Mono font | -V monofont= | "Fira Code" |
| Paper size | -V papersize= | letter, a4, legal |
| Line spacing | -V linestretch= | 1.25, 1.5, 2 |
| Columns | -V classoption=twocolumn | Two-column layout |
| Page numbers | Default | Included automatically |
| Table of contents | --toc | Auto-generated from headings |
| Color links | -V colorlinks=true | Colored hyperlinks |
Pro Tip: When converting code or log files, always use a monospaced font (-V mainfont="Courier New" or similar). Proportional fonts break alignment that is meaningful in code and structured text output.
Method 3: Python Script for Full Control
When you need maximum control over the output, including conditional formatting, dynamic headers, and programmatic page layout, a Python script using the reportlab or fpdf2 library gives you complete freedom.
Using fpdf2
from fpdf import FPDF
import sys
def txt_to_pdf(input_path, output_path, font_size=10, margin=20):
pdf = FPDF()
pdf.set_auto_page_break(auto=True, margin=margin)
pdf.add_page()
# Use a Unicode-capable font for UTF-8 support
pdf.add_font("DejaVu", "", "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf")
pdf.set_font("DejaVu", size=font_size)
with open(input_path, "r", encoding="utf-8") as f:
for line in f:
# Handle empty lines as paragraph breaks
if line.strip() == "":
pdf.ln(font_size * 0.5)
else:
pdf.multi_cell(0, font_size * 0.4, line.rstrip())
pdf.output(output_path)
print(f"Converted {input_path} -> {output_path}")
if __name__ == "__main__":
txt_to_pdf(sys.argv[1], sys.argv[2])
Install the library and run it:
pip install fpdf2
python convert.py input.txt output.pdf
Adding Headers and Footers in Python
class PDFWithHeaderFooter(FPDF):
def header(self):
self.set_font("Helvetica", "B", 9)
self.cell(0, 10, "My Document Title", align="L")
self.cell(0, 10, f"Page {self.page_no()}/{{nb}}", align="R")
self.ln(15)
def footer(self):
self.set_y(-15)
self.set_font("Helvetica", "I", 8)
self.cell(0, 10, "Generated by ConvertIntoMP4", align="C")
This approach is ideal for integration into larger workflows, CI/CD pipelines, or applications that generate PDFs programmatically. If you are building automated conversion pipelines, our guide on automating file conversions covers the broader architecture.
Handling Text Encoding
Text encoding is one of the most common sources of problems in TXT-to-PDF conversion. A file that looks perfect in your editor may produce garbled characters, missing symbols, or outright errors when converted to PDF.
Common Encodings
| Encoding | Description | Use Case |
|---|---|---|
| UTF-8 | Unicode, variable-width | Modern default, supports all languages |
| UTF-8 BOM | UTF-8 with byte order mark | Windows-generated Unicode files |
| ASCII | 7-bit, English only | Legacy systems, simple English text |
| Latin-1 (ISO-8859-1) | Western European languages | Older European documents |
| Windows-1252 | Microsoft's Latin-1 superset | Windows-generated documents |
| Shift-JIS | Japanese text | Japanese legacy systems |
| GB2312 / GBK | Chinese text | Chinese legacy systems |
Detecting Encoding
Before converting, identify the encoding of your text file:
# Using file command (macOS/Linux)
file -i input.txt
# Output: input.txt: text/plain; charset=utf-8
# Using chardet (Python)
pip install chardet
chardetect input.txt
# Output: input.txt: UTF-8 with confidence 0.99
Converting Encoding Before PDF Conversion
If your file uses a non-UTF-8 encoding, convert it first:
# Using iconv
iconv -f WINDOWS-1252 -t UTF-8 input.txt > input-utf8.txt
# Then convert to PDF
pandoc input-utf8.txt -o output.pdf --pdf-engine=xelatex

For batch operations involving multiple encoding types, writing a preprocessing script that detects and normalizes encoding before conversion saves significant troubleshooting time.
Batch Conversion
Converting dozens or hundreds of text files individually is tedious. Here are approaches for automating bulk conversions.
Shell Script (macOS/Linux)
#!/bin/bash
INPUT_DIR="./text_files"
OUTPUT_DIR="./pdf_output"
mkdir -p "$OUTPUT_DIR"
for file in "$INPUT_DIR"/*.txt; do
filename=$(basename "$file" .txt)
pandoc "$file" -o "$OUTPUT_DIR/$filename.pdf" \
--pdf-engine=xelatex \
-V geometry:margin=1in \
-V fontsize=11pt \
-V mainfont="Courier New"
echo "Converted: $filename.txt -> $filename.pdf"
done
PowerShell (Windows)
$inputDir = ".\text_files"
$outputDir = ".\pdf_output"
New-Item -ItemType Directory -Force -Path $outputDir
Get-ChildItem "$inputDir\*.txt" | ForEach-Object {
$outputFile = Join-Path $outputDir ($_.BaseName + ".pdf")
pandoc $_.FullName -o $outputFile `
--pdf-engine=xelatex `
-V "geometry:margin=1in" `
-V "fontsize=11pt"
Write-Host "Converted: $($_.Name) -> $($_.BaseName).pdf"
}
Python Batch Script
import os
import glob
from fpdf import FPDF
def batch_convert(input_dir, output_dir, encoding="utf-8"):
os.makedirs(output_dir, exist_ok=True)
for txt_file in glob.glob(os.path.join(input_dir, "*.txt")):
filename = os.path.splitext(os.path.basename(txt_file))[0]
output_path = os.path.join(output_dir, f"{filename}.pdf")
pdf = FPDF()
pdf.set_auto_page_break(auto=True, margin=20)
pdf.add_page()
pdf.set_font("Courier", size=10)
with open(txt_file, "r", encoding=encoding) as f:
for line in f:
pdf.multi_cell(0, 5, line.rstrip())
pdf.output(output_path)
print(f"Converted: {filename}.txt -> {filename}.pdf")
batch_convert("./text_files", "./pdf_output")
For large-scale batch operations, our batch processing guide covers parallel processing, error handling, and progress tracking strategies.
Formatting Best Practices
Choosing the Right Font
The font you choose has a major impact on readability:
- Monospaced fonts (Courier New, Consolas, JetBrains Mono, Fira Code): Best for code, logs, data files, and any content where character alignment matters
- Serif fonts (Times New Roman, Georgia, Garamond): Best for long-form reading like manuscripts, articles, and books
- Sans-serif fonts (Helvetica, Arial, Inter, IBM Plex Sans): Best for technical documentation, reports, and on-screen reading
Page Layout Recommendations
For standard text documents:
- Margins: 1 inch (2.54 cm) on all sides for printed documents; 0.75 inches for screen-only PDFs
- Font size: 10-12pt for body text; 8-9pt for code listings
- Line spacing: 1.15-1.25 for single-spaced; 1.5 or 2.0 for draft/review documents
- Paper size: Letter (8.5 x 11 in) for North America; A4 (210 x 297 mm) for international
Handling Long Lines
Text files often contain lines that are too long for a PDF page. You have three strategies:
- Word wrap — Break lines at word boundaries (best for prose)
- Character wrap — Break lines at any character (best for data/logs)
- Truncation — Cut lines at the margin (best for fixed-width reports where truncation is acceptable)
- Font size reduction — Shrink the font to fit the longest line (best for preserving alignment in tables)
Special Use Cases
Converting Server Logs to PDF
Server logs often contain millions of lines. When converting to PDF for archival or auditing:
- Filter the log file first to include only relevant entries
- Use a very small font size (7-8pt) with narrow margins to maximize content per page
- Add timestamps as page headers for navigation
- Consider splitting into multiple PDFs by date range
Converting Code Files to PDF
When printing or archiving source code as PDF:
- Use a monospaced font with ligature support (Fira Code, JetBrains Mono)
- Add syntax highlighting using Pandoc's
--highlight-styleoption - Include line numbers with Pandoc's
--number-linesflag - Use landscape orientation for files with long lines
pandoc input.py -o output.pdf \
--pdf-engine=xelatex \
-V geometry:margin=0.75in \
-V geometry:landscape \
-V fontsize=9pt \
--highlight-style=tango
Converting Manuscripts and Books
For authors converting plain-text manuscripts to PDF:
- Use a proportional serif font (12pt) with double spacing
- Set generous margins (1.25 inches) for annotation space
- Add page numbers and running headers
- Consider converting to Word first using our document converter, then formatting in a word processor before final PDF export
If you are working on ebook publishing, our guide on creating EPUBs from Word documents covers the full publishing pipeline, and our EPUB vs PDF comparison helps you choose the right format for distribution.
Preserving Document Structure
Plain text files have no semantic structure, but you can add it during conversion.
Adding a Title Page
With Pandoc, add YAML metadata at the top of your text file:
---
title: "Quarterly Report Q4 2025"
author: "Finance Department"
date: "January 15, 2026"
---
Pandoc uses this metadata to generate a formatted title page automatically.
Generating a Table of Contents
If your text file uses a consistent heading pattern (like lines starting with # or all-caps headings), Pandoc can generate a table of contents:
pandoc input.txt -o output.pdf --toc --toc-depth=2
Page Breaks
Insert page breaks in your text file by adding a LaTeX command where you want the break:
\newpage
Pandoc passes this through to the LaTeX engine, creating a new page at that point.
Comparing Conversion Tools
| Tool | Quality | Speed | Customization | Batch Support | Encoding | Free |
|---|---|---|---|---|---|---|
| ConvertIntoMP4 | High | Fast | Presets | Yes | Auto-detect | Free tier |
| Pandoc | Excellent | Medium | Full | Scriptable | Manual | Yes |
| fpdf2 (Python) | Good | Fast | Full (code) | Scriptable | Manual | Yes |
| ReportLab | Excellent | Medium | Full (code) | Scriptable | Manual | Open source |
| LibreOffice CLI | Good | Slow | Limited | Scriptable | Good | Yes |
| Print to PDF | Basic | Instant | OS settings | No | System default | Yes |
For most users, our PDF converter handles TXT-to-PDF conversion with no setup required. For advanced needs, Pandoc provides the best balance of quality and customization. And for integration into applications and automated workflows, Python libraries give you programmatic control over every aspect of the output.
No matter which method you choose, the key is matching your tool to the complexity of your requirements. A simple text note does not need a LaTeX pipeline, and a 10,000-line log file archive deserves better than a basic print-to-PDF. If you are also working with Word documents, check out our guide on converting Word to PDF for additional formatting tips, or explore the differences between PDF and DOCX formats to choose the right format for your use case.



