1

I am trying to print out thousands of PDFs to a printer called "Print To PDF" this means it will create a new PDF document from an old one.

You may be wondering why I'm doing this and that is because when I print out the new PDF it removes any text boxes implemented onto the PDF.

I have a problem however, when I run my script it say's Save as and asks me to give it a filename which is correct however I'm wondering if there's any way I can tell it to automatically give it a preset filename to save as ?

I don't think it's possible however I thought i'd ask to see if any geniuses can think of something.

Please see my code below:

import os
import sys
import win32print
import win32api

files_to_print = []

for pdf in os.listdir('.'):
    filename_no_ext, ext = os.path.splitext(pdf)
    if ext.lower() == '.pdf':
        if pdf not in files_to_print:
             files_to_print.append(pdf)

for filename in files_to_print:
    CurrentPrinter = win32print.GetDefaultPrinter()

    win32api.ShellExecute (0, "print", filename, CurrentPrinter, ".", 0)

    win32print.SetDefaultPrinter(CurrentPrinter)

If you have any ideas at all please let me know as I am seriously puzzled on this.

Harry Adkins
  • 101
  • 1
  • 10
  • This is for a batch script, but since you are only calling `ShellExecute` anyway, the solution should be the same for your case – FlyingTeller Sep 19 '18 at 08:18
  • Thanks guys, the Windows 10 Print to PDF from command-line link is perfect for what I need. I'm currently implementing it now. Thanks!!!!!!! – Harry Adkins Sep 19 '18 at 08:30

0 Answers0