# How can I print multiple file types in Windows from the command line?

I have setup a PostScript printer called PSPinter to the FILE port. I can go into various programs (MS Word, Excel, Acrobat, etc.), and print the document to this printer. It asks me for a file name, and once it outputs the file, I can examine it and confirm that it is well-formed PostScript. I need to do something like, which behind the scenes invokes the right program and calls the print function on it:

print /d:PSPRinter <inputFile.docx> <outputName.ps>


My question is, how can I do this programatically from the Windows command line? I would also need to be able to specify the output file name. Alternately, I am open to using something like CutePDF to produce the output (I don't care if the output of the files is PDF or (E)PS), but this method would also have to run programatically from the command line.

-

Use the command line ability of PDFCreator to convert any printable file to PDF

1. Install PDFCreator together with its COM interface
2. Create a new text file with the following code and save it as C:\some\folder\Convert2PDF.vbs

Set PDFCreator = Wscript.CreateObject("PDFCreator.clsPDFCreator", "PDFCreator_")
With PDFCreator
.cStart "/NoProcessingAtStartup"
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveFormat") = 0
.cOption("AutosaveStartStandardProgram") = 0
DefaultPrinter = .cDefaultprinter
.cDefaultprinter = "PDFCreator"
.cClearcache
.cPrinterStop = false
.cOption("AutosaveDirectory") = WScript.Arguments(1)
.cOption("AutosaveFilename") = WScript.Arguments(2)
.cPrintfile cStr(WScript.Arguments(0))
c = 0
Do While (ReadyState = 0) and (c < 120)
c = c + 1
Wscript.Sleep 250
Loop
.cDefaultprinter = DefaultPrinter
.cClearcache
WScript.Sleep 200
.cClose
End With

End Sub


### Usage

CMD> C:\some\folder\Convert2PDF.vbs "C:\inputfile.doc" "C:\outputfolder" "outputfilename"

-
Thank you! - This looks great! I have yet to try it out... –  cbannerjee Jul 22 '13 at 13:43
I had downloaded PDFCreator, but I need admin rights to install it... the corp. IT guys need to give me permission first... –  cbannerjee Jul 22 '13 at 13:43
Worked - thanks very much. Also, for those interested, there are a ton of examples under the PDFCreator install under the COM folder. These make the usage much clearer. –  cbannerjee Jul 30 '13 at 19:27

You can print to file printers from word with the Application.PrintOut method. See http://msdn.microsoft.com/en-us/library/office/ff840681.aspx for more info.

Set WordApp = CreateObject("Word.Application")
Set oArgs = Wscript.Arguments
doc = oArgs.Item(0)
'printer
prt = oArgs.Item(1)
'prt = "4550PS"
' open the document
WordApp.Documents.Open(doc)

' set printer
WordApp.WordBasic.FilePrintSetup prt,,,1

' print docx file to ps file
'OutputFileName = left(doc, len(doc) - 4)&"ps"
OutputFileName = oArgs.Item(2)
WordApp.ActiveDocument.PrintOut ,,, OutputFileName,,,,,,, True

WordApp.ActiveDocument.Close False
Set WordApp = nothing
Set oArgs = nothing


You run the above vbs file as follows: file.vbs c:\my\path\to\input.docx MyPrinter c:\my\path\to\output.ps

Make sure your printer names do not contain spaces ....

I choose the "HP Color LaserJet 4550 PS" for colour PS files, I name it 4550PS in windows.

-