“Now witness the firepower of this fully armed and operational
battlestation enscript replacement”.
Back in the day, when OSU had licenses for Adobe TranScript to drive all the laser printers on campus, I was pretty much the only person who really understood how it worked. So much so that after I left for California, the Physics department’s sysadmin gave me an account on his servers to help him get a new version to work.
Somewhere along the line, Adobe stopped actively supporting PostScript
(having given up the rights in order to make it a public standard),
and TranScript went away, taking with it the extremely useful
enscript
text-to-PostScript utility.
Which was reimplemented a-bit-too-faithfully by GNU folks, and then crufted up with useless garbage. Mind you, full compatibility already made it pretty crufty, because the original Knew Way Too Much about how Unix PostScript printer management worked in the late Eighties and early Nineties. What GNU-enscript hasn’t done is keep up with the times: the last release was 12 years ago.
No features. No fixes. No Unicode. No OpenType fonts. No PDF output.
That last bit was particularly grating for me, because a few releases
back, Apple abandoned PostScript rendering completely, so the only
convenient way to print decades of documents is by shoving them
through GhostScript’s ps2pdf
, which
works, if you’re comfortable with their
history of not taking security seriously
(grumblegrumble getoffamylawn).
[yes, the free Acrobat Reader still exists, and handles PostScript, but it’s slow to launch and crufted up with Adobe’s attempts at revenue extraction; I have the full Acrobat Pro from the Adobe CC suite, and it’s even slower and cruftier]
I just wanted Unicode text, set in any available fixed-width font, neatly paginated with page numbering and headers/footers, written directly to a PDF file. There are a number of open-source tools that advertise some of these capabilities, but all the ones I’ve tried suck to some degree. Writing my own has been an idea gathering dust in my note-taking apps for several years, but after completing my rewrite of longpass in Python, I decided to finally take a stab at it.
First up, the name: I’ve kept track of all the text-to-pdf tools I
came across, brainstormed to find something better, then googled to
see which ones had unfortunate connotations. TL/DR: I’m not happy with
it, but uc2p
is at least short, inoffensive, and fairly unique, so
that’s been the working name of the project.
Second, the code. Porting the box
and paper
modules from
PDF::Cairo gave me flexible
layout and styling, and after abandoning
ReportLab’s Platypus subsystem in favor
of the lower-level PDFgen, I was quickly able to knock together some
prototypes over the past few days.
The code (~1,200 lines, including libraries) needs a cleanup pass and
a real config file for styles, but here’s a sample page of
output in the
classic -2rGL66
style (two-up, rotated, gaudy headers, 66
lines/page).
By the way, at least with later versions of Adobe’s enscript and with
the GNU clone, that -L 66
doesn’t actually do anything useful; -l
auto-resizes the font to put exactly 66 lines on each page or column,
but it’s incompatible with any page headers or footers. It was kind of
an accident that -2rGL66
ever worked as expected; IIRC, it got
broken by a margin change in the template in Adobe’s version, and that
was faithfully copied by GNU.
What -L N
actually does is ensure that no more than N lines will
appear on a page. So you could leave the bottom half of the page blank
by setting -L 30
, for no good reason. My new script, on the other
hand, always fits exactly N lines into the space.
Anyway, I’m abandoning drop-in compatibility, so I’m currently going
through the various options, giving sensible single-letter
abbreviations to the most common ones and moving the rest to a
catchall -O opt1=val -O opt2 ...
. Which will match the structure of
the config file where I define layout styles.
Just for fun, a few people out there still have extremely stale web
sites, so it’s possible to see what options the Adobe version had in
1992. I love that
multi-column printing was under -v
, and that there were two
completely different one-character options for “send email after job
prints” (-w
and -m
).
And of course everything related to “job burst pages”, something that I haven’t seen in so long that I forgot it was a thing.
“Dear Amazon, why are you so forcefully recommending a book on talking to small children about sex? I’m pretty sure I’ve never bought anything that would make that relevant for me, or I’d have already gotten a knock on the door from federal agents…”
Markdown formatting and simple HTML accepted.
Sometimes you have to double-click to enter text in the form (interaction between Isso and Bootstrap?). Tab is more reliable.