For a project i'm working on, I need to be able to write to a text file and then send that file to the printer. I'm fairly new to programming (1.5 yrs) and in my time have never needed to do this.
So, my question is how would I send the file to the printer? (Obviously I know how to write to the file in the first place). I need the program to work on windows XP and windows 7, I've come across something called the lpr online but I can't find anything substantial, and this seems to be related to UNIX based OS'es.
I have a feeling I may need to use os.system() somewhere but am unsure how I would go about this.
A simple approach is to have Notepad print the text file:
import subprocess
subprocess.call(['notepad', '/p', filename])
I did this a long time ago, so I don't remember the specifics, but it involved going through a win32 extension for python to call the Windows API related to printing.
You may also consider options such as generating a pdf file.
You may find the following links useful:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With