Older multivalue application still print using a page format of either 132 chars by 66 lines or 80 chars by 60 lines. It would be nice if they could be converted to a PDF format for distribution. This is a simple Python script that can convert a .txt file to a PDF using a Python command line. The command line can be executed from a BASIC program. The landscape mode works only on 132×66 and the portrait mode only works with 80×60.
Usage: txt2pdf.py [land|port] inputpath.txt outputpath.pdf
Required: Needs the fpdf package. pip import fpdf
import sys
from fpdf import FPDF
orient = sys.argv[1]
infile = sys.argv[2]
outfile = sys.argv[3]
if orient == “land”:
pdf = FPDF(‘L’, ‘in’, ‘Letter’)
font_height = 0.12
else:
pdf = FPDF(‘P’, ‘in’, ‘Letter’)
font_height = 0.16
pdf.add_page()
pdf.set_margins(0.25, 0.25)
pdf.set_auto_page_break(True, margin = 0.25)
if orient == ‘land’:
pdf.set_font(‘Courier’, ”, 8)
else:
pdf.set_font(‘Courier’, ”, 10)
pdf.set_xy(0.25, 0.25)
f = open(infile)
for line in f:
pdf.write(font_height, line)
f.close()
pdf.output(outfile, ‘F’)