Converting text to PDF creates a universally viewable, professionally formatted document from plain content. Whether starting from a .txt file, an RTF document, or plain text content, multiple methods produce clean PDF output on any operating system.
Convert Plain Text to PDF via Word or LibreOffice
Open the .txt file in Microsoft Word or LibreOffice Writer. Go to File, then Save As in Word or Export as PDF in LibreOffice. Both applications apply default formatting — margins, fonts, page size — and produce a well-formatted PDF from the plain text content.
Convert Text to PDF Using Python
from fpdf import FPDF
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size=12)
with open("document.txt") as f:
for line in f:
pdf.cell(0, 10, txt=line.strip(), ln=True)
pdf.output("document.pdf")
The fpdf library creates PDF files programmatically from Python. Install with pip install fpdf2. This approach is useful for automated PDF generation from dynamic text content in scripts and applications.
Convert via Command Line
pandoc input.txt -o output.pdf
Pandoc is the universal document converter available on Mac, Linux, and Windows. It converts plain text, Markdown, RTF, HTML, and many other formats to PDF. Install from pandoc.org and run a single command to convert any text file.
Frequently Asked Questions
How do I convert multiple text files to PDF at once?
Using pandoc in a shell loop: for f in *.txt; do pandoc “$f” -o “${f%.txt}.pdf”; done. LibreOffice also supports batch conversion: libreoffice –headless –convert-to pdf *.txt. Python scripts with fpdf or reportlab can process any number of files in a loop.
Will my text formatting be preserved when converting to PDF?
Plain text .txt files have no formatting — the PDF uses the application default (font, size, margins). RTF files retain their formatting when converted via Word or LibreOffice. For precise control over the PDF appearance, use Python with reportlab or weasyprint, which accept CSS-style styling.