I am trying to use Microsoft's Print to PDF to automatically save multiple PDFs files to a directory. The code below prompts me to save each file manually.
How can I programmatically control this with Python to not prompt to enter the PDF filename but to automatically save to a directory I provide?
The main reason I want to do this is because I am trying to merge multiple financial statements for a report. Some of the statements are protected to allow for viewing only and not editing, and, therefore, I cannot merge them. A way around this is to use Print to PDF, which creates a copy that I can then edit and merge with other PDFs.
I am using the Win32api module, but I am open to any other alternative programmatic ways of doing this.
import win32api
import win32print
all_printers = [printer[2] for printer in win32print.EnumPrinters(2)]
win32print.SetDefaultPrinter(all_printers[3])
win32api.ShellExecute(0, "print", file, my_printer, ".", 0)