September 30, 2022

Windows -- printing a file

If you just have a random text file, there seems to be no way to just print it, which I find surprising. What does work is to find Notepad and start it up. Then use "File -- open" to pull the file into Notepad, then select "File -- print" to print it.

There is a "print" command I can invoke from the command line, but when I try using it, I get the message "Unable to initialize device PRN". Well that is odd given that Notepad knows how to print.

Some digging suggests that PRN by default goes to LPT1: which at some point in the ancient past was an old parallel port.

One suggestion is to use "print /d:printer-name file", but now my question is what is the printer name I should use?

I go to Settings--Devices--Printers and Scanners. I see my Brother printer in the list and select it. Then I select "Manage", then "Printer properties". Here I could change the printer name, but for now I will just note that the name is:

Brother HL-L2370DW series Printer

So I try the command print /d:"Brother HL-L2370DW series Printer" try.py and it tells me that my file is being printed, but nothing happens. In fact I get the message regardless of what I put after the /d: switch.

Another tip is to use powershell and "Start-Process -FilePath="try.py" -verb Print. This seems a bit esoteric. I am starting to remember why I hate windows so much.

Another suggestion is to bounce the file through notepad via:

notepad /pt try.py
I just get bizarre errors from Notpad when I try this. I am giving up on this, something I would have expected to be totally simple.

Conclusions

Printing in the Windows world is more convoluted and definitely different than I expected. First of all, I think the "print" command is an obsolete and disfunctional legacy command. Maybe it could be made to work if I could redirect "PRN" to point to my printer.

Forgetting about "print", the Windows view seems to be that you don't just print arbitrary files. They have this idea of "associating" files (based on file extent such as ".txt") with some application that understands the file. The application may then have a print option or it may not. If not, there is no way to print the file, and in the windows view, the file is unable to be printed. This is certainly the case for binary files (such as a ".exe" file).

If this view is right, then I use notepad as the gadget to print plain text files. If I want to print a postscript file, I need an application like "gsview" or perhaps "gsprint". Or I can dive into the Windows programming API and add a print functionality to a program I might write.


Have any comments? Questions? Drop me a line!

Adventures in Computing / [email protected]