Thanks MRAB. I tried this and got an error message, but a beautifully
clear one:
TypeError: StartDocPrinter() argument 3 must be 3-item sequence,
not dict
So I changed it thus:
doc_info = ("Raw FF Test", None, "RAW")
The good news: it printed. Well, the first time I ran the program it did.
The bad news: it printed the same as before: all on one page, with the
form feed displayed as an arrow character.
Moreover: when I re-ran the program the printer did not respond,
apparently not seeing any print requests,
although the jobs piled up in the print queue when I looked at it.
(Something to do with spooling?)
I tried
clearing the print queue manually and turning the printer on and off
changing "RAW" to "raw" or to None
but still couldn't persuade it to print again.
The win32print.StartDocPrinter documentation doesn't get me any further.
According to
https://learn.microsoft.com/en-us/windows/win32/printdocs/startdocprinter
you are doing all the right things, as far as I can see.
I expect it would print again if I rebooted the laptop, but that's not
convenient at the moment.
Stuck.
What the hell, I'll just feed the paper back in. 🙂
Best
Rob
On 27/08/2026 17:42, MRAB wrote:
On 27/08/2026 16:16, Rob Cliffe via Python-list wrote:
Thanks Pierre and MRAB.
I tried that; here is a hex dump of my concatenated file:
16:09:12 R:\DSPR>dump ShortDocument3.txt
File ShortDocument3.txt Size 60 (hex 3C) bytes
00000000: 54 68 69 73 20 69 73 20 74 68 65 20 66 69 72 73 |This is
the firs|
00000010: 74 20 64 6F 63 75 6D 65 6E 74 2E 0D 0A 0C 54 68 |t
document...♀Th|
00000020: 69 73 20 69 73 20 74 68 65 20 73 65 63 6F 6E 64 |is is
the second|
00000030: 20 64 6F 63 75 6D 65 6E 74 2E 0D 0A |
document... |
but no dice; it printed the whole thing on one sheet, with the form
feed printed as a
thick-headed up-arrow character at the start of the second line.
It's looking as if it will only switch sides when the first side is
full.
[snip]
Apparently you need to print in "RAW" mode, otherwise the printer
driver will just discard the Form Feeds.
I asked Copilot, and it came up with this example code (not tested
because I'm on Linux now). Good luck!
import win32print
import win32api
printer_name = win32print.GetDefaultPrinter()
hPrinter = win32print.OpenPrinter(printer_name)
doc_info = {
"pDocName": "Raw FF Test",
"pOutputFile": None,
"pDatatype": "RAW"
}
win32print.StartDocPrinter(hPrinter, 1, doc_info)
win32print.StartPagePrinter(hPrinter)
with open("myfile.txt", "rb") as f:
data = f.read()
win32print.WritePrinter(hPrinter, data)
win32print.EndPagePrinter(hPrinter)
win32print.EndDocPrinter(hPrinter)
win32print.ClosePrinter(hPrinter)
--
https://mail.python.org/mailman3//lists/python-list.python.org