This Python program, batch_text_to_pdf.py, can create a PDF file from a batch of text files.
It uses my xtopdf toolkit, ReportLab and Python.
It also uses the fileinput module from Python's standard library.
The fileinput module is quite useful for creating Unix-style command-line programs in Python, that process a batch of text files, like awk, sed, and other similar Unix tools can.
The basic pattern for these commands is:
command_name file1.txt file2.txt ...
from PDFWriter import PDFWriter
# Hard-coded for now,
# should take PDF name from
# command line, by skip-
# ing first name for fileinput.
pw = PDFWriter('output.pdf')
pw.setHeader('Batch text files to PDF')
pw.setFooter('Created by xtopdf')
for line in fileinput.input():
The program has no error checking and can be improved some (e.g. see the comment in the code); this is just a quick demo.
Run it like this:
python batch_text_to_pdf.py file1.txt ...
where the ... means (optionally) more text file names.
The combined output should then be in file output.pdf.
Use ReportLab v1.21, not v2.x.
Posted via mobile, sorry for narrow post width.
- Vasudev Ram