Search code examples
windowspdfprintingvirtual-printerflatten-pdf

Windows 10: Simple way to print a PDF-file without the save-dialog


I'm trying to print the PDf-file(s) in a certain folder (or alternatively just print the files one-by-one) using for example Micorosft Print to PDF in order to create flattened versions. However when using Microsoft Print to PDF i need to specify the ouput-file's name and path. Is there any way to circumvent this or an alternative virtual printer specialized on such a job?

What I've already tried:

Windows 10 Print to PDF from command-line and Printing PDFs from Windows Command Line

These approches try to use the command prompt (personally favoured by me aswell, as it allows to create a batch-file and automate the process completely), but unfortunately the programs/printers listed in those posts are either not free or show a save-file-dialog aswell. Furthermore they are quite slow (even though this is not my main focus). So far, PDFtoPrinter has been the best solution, though it shows the save-file-dialog aswell...

Another idea I got from this post is to create a (VBA-/PowerShell-)script, but I'm not very experienced at that.

Any way to print just one PDF via the console and then making a loop or maybe even hard-coding the names would suffice aswell. I can easily rename the files for example to 1.pdf, 2.pdf, 3.pdf, ...

At this point I've tried so much but there has to be a way to get this running. Any help would be greatly appreciated!


Solution

  • Microsoft Print to PDF on Windows is not "Free", simply "Leased", however that said you can change the owners designed behavior to a different "port" than "prompt" or use the drivers to print to your desired named file.

    To use ONE fixed output filename like %TEMP%OUT.PDF you are best served by cloning/duplicate the "Microsoft Print to PDF" to a printer name of your choice so I call mine "My Print to PDF" as its shorter to type and the Auto printed file goes to MyData folder. For a visual guide see https://stackoverflow.com/a/69169728/10802527 and up vote there if that helps.

    The alternative is to use a structure like

    CliPdfApp /PrintTo file.pdf "Microsoft Print to PDF" "Microsoft Print to PDF" "C:\MyFavourite Places\FileName.pdf
    

    However few apps follow the required convention, so WordPad will convert Docx or RTF via command line but can not handle a PDF and Edge AFAIK was not designed to make the PDF format CLI print friendly :-). But those links you have in the question will suggest acrord32 /p or /t filename printer printdriver filename and that is probably the best method for flattening acroforms

    Disclaimer I support SumatraPDF so can suggest to "Print As Image ONLY" its perfect as one single 32 or 64 bit portable.exe https://www.sumatrapdfreader.org/prerelease so all you need is:-

    SumatraPDF -print-to "My Print to PDF" filename.pdf (or other types supported)

    There are other print methods/options but BE-AWARE that is NOT flattening forms since "Flattening" means convert the form to plain readable text and SumatraPDF ONLY prints PDF as Imagery.

    So combining SumatraPDF with a promptless port will provide a single command to build a known output then you need to monitor that output and rename to one of your choice, that can be tricky if you are submerged and "running silent and deep" without GDI feedback (that the print is spooling/erroring) and time is as variable as the input PDFs complexity.

    You use the word "Slow" but that is the innate feature of PDF "Slow and Steady" output are its designed aims.

    As an alternative to SumatraPDF two other viewers are more geared towards PDF Command Line printing. One is Acrobat Reader as per above "/Terminate and Stay Resident" and it does that exceptionally well so should be preferred. A good alternative lightweight but powerful PDF handler is Tracker PDF X-change which has both command line printing and its own programmable printer drivers.