2

I'm correcting assignments from my students right now and I'd like to automate an annoying step I always have to do.
After annotating their PDF solutions, I need to Print them to PDF files in order to bake my annotations into the PDF so that they can be included in LaTeX. Right now I have to manually choose "Microsoft Print to PDF" and enter the PDFs name with a leading underscore (which is what my automatically generated LaTeX files expect). This gets annoying for 30+ files.
So I'd like to issue this in a batch-script automatically for all the PDFs to minimize my efforts to a simple double-click. I have seen that this is possible with e.g. C# (Here), but I'd like a solution with a simple batch script.
Can this be done?

Edit:
The C#-Code I found actually does not get the Job done. You can't print existing PDFs that way. I'd need to use Spire.PDF to do that. The Free Version however messes up the PDF; I can download the "Full" version in NuGet, this however generates a disclaimer at the beginning of any PDF, and it still can't handle things I draw in Adobe Reader DC. So C# really is not an option, I need a command-line solution.

clocktown
  • 371
  • 1
  • 3
  • 10

2 Answers2

0

You'll better install pdfcreator

and use the commandline options

SachaDee
  • 9,245
  • 3
  • 23
  • 33
  • This looks promising, unfortunately when I try to run it via commandline as stated in your link, I always get the error "The following files can't be converted [...]". – clocktown Jun 19 '17 at 20:45
  • Okay, I got it to work by _not_ using pdfcreator's commandline options, but Acrobat Reader DC's commandline options, where I specified my custom printer I created with pdfcreator. That printer simply autosaves the file with a leading underscore. It works as expected! `cmd /c "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /t C:\temp\MyPDF.pdf "MyCoolPrinter"` – clocktown Jun 19 '17 at 21:10
  • How did you make your custom pdfcreator printer autosave the file with a leading underscore? – Daniel Norberg Feb 12 '20 at 14:37
  • broken link for command line options, use this: https://docs.pdfforge.org/pdfcreator/en/pdfcreator/using-pdfcreator/command-line-parameters/ – johnnyontheweb Oct 17 '22 at 10:13
0

I assume it should be quite easy using PowerShell, but I ran into the same problem as described in this post. The PowerShell solution from here creates only blank PDF files for me.

There probably exist better solutions, but I managed to combine PDFtoPrinter and this post.

A batch script could look like this:

for /R %%f in (*.pdf) do (
    (echo with createobject^("wscript.shell"^)
    echo .run "<path to PDFtoPrinter.exe> ""%%f"""
    echo wscript.sleep 3000
    echo .sendkeys """%%~df%%~pf%%~nf_correction.pdf"""
    echo .sendkeys "{enter}"
    echo wscript.sleep 3000
    echo end with) > %temp%\sk.vbs
    start /w %temp%\sk.vbs
)

This script uses Microsoft Print to PDF to create corresponding files of the format <filename>_correction.pdf.

The batch script creates an sk.vbs script in %temp% and runs it. The sk.vbs script then handles the file saving dialog of Microsoft Print to PDF.

Additionally, this solution has the drawback that you can't use your computer while the script runs because the sk.vbs script must send keys to the window in focus.

upe
  • 1,862
  • 1
  • 19
  • 33