Skip to main content
Topic: Script to print to PDF (Read 15304 times) previous topic - next topic

Script to print to PDF

I doubt anyone will have a need for this script, as I did, but thought I'd post it anyway.  Apologies in advance if wasting your time.  And if someone has a similar script done with "AutoIt" instead of VBScript, I'd be interested in it.

Attached script automates key sequences needed to print current song in NWC to PDF file (song need not be saved to a file).  Script was written to expect PDFCreator 0.9.6, but I believe it can easily be modified for other PDF printers if needed.  Script allows for an optional command-line option which becomes a differentiating suffix for the PDF file.

Script does "inject" key presses, which I'm not a big fan of, but it has some safeguards.  It only does key presses, and never does mouse clicks.  It makes every attempt to ensure correct application has focus before injecting key presses.  It does nothing to the NWC session (or the original file), but instead spawns a separate NWC Viewer (via a temporary file) to do the printing (script can be greatly simplified if one is comfortable injecting to NWC itself - I was not).

I use this script in conjunction with "Run User Tool", so that a single user tool invocation can sequence some automated conversions and then print the result to a PDF, followed by a revert and running another similar user tool to create and print an alternate version, and so on.  Each top-level user tool automatically does everything needed to create and print its specific version.

Invocation command for general use is: wscript scripts\prw_PrintToPdf.vbs "<PROMPT:Suffix:=*>"

Drop ".txt" from file name after downloading.  Specify "File Text" for "Input Type".  Specify "Long Task Handling" option.

Re: Script to print to PDF

Reply #1
Sorry, I must be sleepy. What's the use of such a program?
Isn't easier (or virtually the same) to use "file->print->PDFCreator" as I do so often?

Re: Script to print to PDF

Reply #2
What is the idea of any script, but to automate a process which would be tedious to manually do otherwise?!

I found myself doing the following 5 separate times for every hymn I entered:
  • Click on "File", Click on "Print" (or Ctrl-P)
  • Wait for Print box to come up
  • Choose "PDFCreator" for printer (if not already there)
  • Click on "OK"
  • Wait for PDFCreator window to come up
  • Click on "Save"
  • Wait for Save As box to come up
  • Click on end of File Name
  • Enter differentiating suffix [" (C)", " (Bb)", " (F)", " (Eb)", or " (C-alto)"]
  • Click on "Save"

If you find that doing this process so often is easier (or virtually the same) than running a single user tool, you're perfectly welcome to do so!  I have no illusions that this script is a great time-saver for everyone - it just works well for me, and I thought I'd share it, just in case.  Again, apologies if I'm further wasting anyone's time here.

[Using RunUserTool and other scripts, I am fast getting to the point where a single user tool invocation can automatically generate all 5 of my PDFs for a hymn (for C instrument, Bb instrument, F instrument, Eb instrument, and C instrument alto clef).  This PrintToPDF script was a part of that automation process.]

Re: Script to print to PDF

Reply #3
Quote
I am fast getting to the point where a single user tool invocation can automatically generate all 5 of my PDFs for a hymn (for C instrument, Bb instrument, F instrument, Eb instrument, and C instrument alto clef).  This PrintToPDF script was a part of that automation process.

Aha, this makes a lot more sense!

Quote
Again, apologies if I'm further wasting anyone's time here.

Oh, I think I'll survive... ;-)
Out of joke: mine was not a critic, I was simply curious.