(800) 219-8613 sales@ashwoodcomputer.com

Short Python program to convert a .txt to a PDF

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
    pdf = FPDF(‘P’, ‘in’, ‘Letter’)
    font_height = 0.16

pdf.set_margins(0.25, 0.25)
pdf.set_auto_page_break(True, margin = 0.25)
if orient == ‘land’:
    pdf.set_font(‘Courier’, ”, 8)
    pdf.set_font(‘Courier’, ”, 10)
pdf.set_xy(0.25, 0.25)

f = open(infile)
for line in f:
    pdf.write(font_height, line)
pdf.output(outfile, ‘F’)


Ashwood Computer, Inc.

10671 Techwoods Circle Cincinnati, Ohio 45242

(800) 219-8613
(513) 563-2800

(513) 554-6412

Our Value – Added

Ashwood Computer, Inc. provides quality products and services that consistently meet our customer’s requirements, while continually searching for ways to improve them.

Our experienced project managers will help you successfully accomplish your goals on time and with optimum results! Our continuing success is attributed to the diverse backgrounds of our technical staff and our overall company drive for Total Customer Satisfaction!

ForeMost ERP is an impressive new ‘Hybrid’ Solution developed utilizing our mvTools.
ForeMost is dramatically improving our customers information systems and business operations. Moreover ForeMost provides our customers a significant competitive advantage!

© 2021 Ashwood Computer, Inc.
Ashwood Computer adheres to ISO 9001:2008 standards, a quality management system recognized around the world for quality design and production.