Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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
     ReadyState = 0
     .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
    
    Public Sub PDFCreator_eReady()
     ReadyState = 1
    End Sub
    

Usage

CMD> C:\some\folder\Convert2PDF.vbs "C:\inputfile.doc" "C:\outputfolder" "outputfilename"
share|improve this answer
    
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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.