I'm struggling with printing PDF files, but this Q/A helped me a lot, especially post Nr. 2
My question is: Is it possible to automatically print 2 different PDF files on 2 different printers in one script?
Using the code of the linked Q/A, I get the following result:
Choose a printer:
0 OneNote (Desktop)
1 Microsoft XPS Document Writer
2 Microsoft Print to PDF
3 HP584853 (HP DeskJet 3700 series)
4 Fax
5 Brother QL-570
6 Brother MFC-9142CDN Printer
7 Adobe PDF
As I do not have a second physical printer, I decide to go for "Adobe PDF", the code is made for a friend, who has more printers, so the final code will not print to "Adobe PDF", but I would like to prepare the code at home and then change it, once I see him.
Re-writing the code to my "needs" (the code itself is way more complicated and will use tkinter etc., but to keep it simple I wrote it less extensive)
import win32api
import win32print
from glob import glob
all_printers = [printer[2] for printer in win32print.EnumPrinters(2)]
win32print.SetDefaultPrinter(all_printers[5])
pdf_dir1 = "C:/Users/fabia/Desktop/A.pdf"
for f in glob(pdf_dir1, recursive=True):
win32api.ShellExecute(0, "print", f, None, ".", 0)
win32print.SetDefaultPrinter(all_printers[7])
pdf_dir2 = "C:/Users/fabia/Desktop/B.pdf"
for g in glob(pdf_dir2, recursive=True):
win32api.ShellExecute(0, "print", g, None, ".", 0)
input("press any key to exit")
When I run this code, both files are printed on printer [5], "B.pdf" is printed first.
How can I print A.pdf on [5] and B.pdf on [7]?
I also tried working with the os package:
os.startfile(pdf_dir1, "Print")
This works, but I do not know how to use 2 printers.