💾 Archived View for tilde.pink › ~bencollver › log › 2022-06-15-print-quest captured on 2022-07-16 at 13:49:43. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

2022-06-15 - Print Quest

I wanted to print from DOS applications, but i no longer have a hardware printer. After some tinkering, i came up with the following solution in FreeDOS. Note that this process does not work in dosbox nor in dosbox-x.

The first thing i learned is that the most common type of printer for DOS is Epson Esc/P. See the link below for a detailed reference to Esc/P printer language.

Esc/P Reference

First, the ingredients for this recipe:

Ghostscript (FreeDOS)

Ladybug LOGO (Simtelnet)

NetPBM (DJGPP)

PRN2FILE (Garbo)

SNARF screen shot utility

EscParse Esc/P to PDF/PS/SVG converter by Nikita Zimin

Filter to fix Epson printer graphics output by NetPBM

I chose to use Ladybug LOGO, which i described in an earlier log entry:

Ladybug Quest

I unzipped all of the "ingredients" and made sure they were in my path.

I saved a simple LOGO program called flwrlife.bug:

C:\>cd \ladybug
C:\ladybug>copy con flwrlife.bug
to circle :size :angle
repeat ( 360 / :angle ) [ fd :size rt :angle ]
end
home cs ht rt 90 repeat 6 [ circle 1 1 rt 60 ]
^Z

Note: Where it shows ^Z, i pressed Ctrl-Z and then Enter.

I ran the snarf screen shot utility, then ran the LOGO program:

C:\ladybug>snarf.exe
C:\ladybug>ladybug.exe
? load flwrlife.bug

I pressed Alt+S to take a screenshot.

Ladybug flower of life screenshot

I quit LOGO:

? bye

I converted the screenshot to Esc/P data using NetPBM. By the way, when i run NetPBM's Epson graphics through a printer emulator, the graphical output is staggered and incoherent. For this reason i wrote escpfltr to add a carriage return before each line of graphics and unstagger them.

C:\ladybug>bmptoppm.exe SNARF000.BMP >flwrlife.pnm
bmptoppm.exe: Windows BMP, 320x200x4
C:\ladybug>ppmtopgm.exe flwrlife.pnm >flwrlife.pgm
C:\ladybug>pgmtopbm.exe flwrlife.pgm >flwrlife.pbm
C:\ladybug>pnmmerge.exe pnminvert flwrlife.pbm >inverted.pbm
C:\ladybug>pbmmerge.exe pbmtoepson inverted.pbm >inverted.esc
C:\ladybug>escpfltr.com <inverted.esc >flwrlife.esc

I found an old utility named prn2file that captures the print job being sent to the printer. It works even when there is no printer attached. I used options to save to C:\print.out using a 64KB buffer. Note that prn2file does not work in dosbox nor in dosbox-x.

C:\ladybug>prn2file.com /b64 /f C:\print.out
 PRN2FILE 1.1 (c) 1987 Ziff Communications Co.
Modifications (c) 1991 Automated Answers
LPT1 Redirected to: C:\print.out

Then i used the COPY command to "print" the screenshot. It is important to pass the /b option. This uses an ioctl() to set binary mode. Otherwise, DOS will truncate the print data the first time it sees a Ctrl-Z (ASCII character 26, SUB). I used prn2file to ensure that the whole print job was flushed to disk.

C:\ladybug>copy /b flwrlife.esc prn
C:\ladybug>prn2file.com
 PRN2FILE 1.1 (c) 1987 Ziff Communications Co.
Modifications (c) 1991 Automated Answers
LPT1 Redirected to: PRN

Then i compared the captured print job data to the original file.

C:\ladybug>comp flwrlife.esc \print.out
Files compare OK.

What can i do with these captured print jobs on DOS? The "escparse" utility can convert Esc/P to PDF. I could copy the PDF to a thumb drive and print it from another computer. Because the DOS PDF viewers don't work well for me, i'll also convert the PDF to JPEG page images to preview using the links browser.

C:\ladybug>escparse.exe -pdf C:\print.out >flwrlife.pdf
ESCParser utility  by Nikita Zimin  Jun 15 2022 17:08:37
Pages total: 2
Page 2
C:\ladybug>gs.exe -r72x72 -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sDEVICE=jpeg -dJPEGQ=90 -o page-%03d.jpg flwrlife.pdf
GPL Ghostscript 8.71 (2010-02-10)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
Page 2
C:\ladybug>c:\freedos\net\links\links.exe -g -mode 640x480x64k page-001.jpg

Screenshot of page image in links browser

Now that was a pretty convoluted process but it has a few advantages.

Whew! That's enough for now.

tags: bencollver,retrocomputing,technical

↩ Back