7

Is there a way to run a file through a print driver without opening the application?

Ex: run a .docx file, without opening word, and save it to file?

Tom V
  • 1,498
  • 18
  • 24
robblot
  • 395
  • 2
  • 5
  • 15

5 Answers5

11

Since it is a .docx-file Microsoft Word is probably the best program to do the task.

I would have a look at the [command line arguments] to Word:

Have a look at the following switches:

/q, /n, /mFilePrintDefault and /mFileExit

(/q and /n explained in the page above, and /mXxxx refers to macros. Have a look att google.)

Example:

WINWORD.EXE your_document.docx /mFilePrintDefault /mFileExit /q /n

The following page seems to explain how to convert it to PDF.

Ber
  • 40,356
  • 16
  • 72
  • 88
aioobe
  • 413,195
  • 112
  • 811
  • 826
  • I had to use `/mFileCloseOrExit` to get the Word closed. – Passiday Aug 06 '20 at 21:15
  • Also, I discovered that the printing will fail if the document has outside of the printable area. Word pops up a warning and never gets to the printing. The workaround was to create a [special macro](https://www.vbforums.com/showthread.php?710129-RESOLVED-VB6-Word-How-can-I-avoid-margin-warning-messages) SpecialPrint in Normal.dotm that suppresses this warning, and use `/mSpecialPrint` instead of `/mFilePrintDefault` – Passiday Sep 28 '20 at 17:47
0

What you are looking for is called "headless start" of the program which needs to print. I know for sure that OpenOffice can do this. Basically, you need to start it and invoke a macro which will do the printing. Even more, you can print to a PDF, HTML, or anything else that Oo supports.

This negates the need for install of Microsoft Word and the cost of license, because OpenOffice is free.

Vanco
  • 519
  • 1
  • 6
  • 11
0

If

  • you have problems with Macro warnings;
  • you are able to modify the default printer to be PDF Printer or similar;
  • and you have the ability to add or record Macros.

Add something like this to normal.dotm:

Sub CmdPrint()
'
' CmdPrint Macro
'
'
    Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
     wdPrintDocumentWithMarkup, Copies:=1, Pages:="", PageType:= _
     wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
     PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
     PrintZoomPaperHeight:=0
End Sub

Then call from the command line as detailed above, such as:

@echo off & setlocal
set ProjectFolder=%USERPROFILE%\Projects
set Project=MyTest
set DocType=docm
start winword "%ProjectFolder:\\=\%%Project%.%DocType%" /q /n /mCmdPrint mFileCloseOrExit
Ian Lowson
  • 11
  • 3
-1

You might be interested in DocTo which will convert a word document to another file format, including pdf and XPS but does require Word on the machine.

For example

Docto -f "c:\docs\mydocument.docx" -o "c:\output" -t wdFormatPDF 

Will output mydocument.docx to c:\output\mydocument.pdf as a pdf file.

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
-1

If you are looking only for .docx silent printing then [aioobe] answer is the best. If you want a more generic silent print program that runs on Windows, use powershell or .NET and use the print verb. http://www.eggheadcafe.com/software/aspnet/30441939/how-to-suppress-printdialog-when-using-print-verb.aspx provides an example.

Hope this helps, if so +1 please :)

Nitin Unni
  • 358
  • 1
  • 6