如何从命令行打印文件?

发布于 2024-08-31 03:36:58 字数 76 浏览 2 评论 0原文

有没有办法通过打印驱动程序运行文件而不打开应用程序?

例如:运行 .docx 文件,而不打开 Word,并将其保存到文件?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

仙女 2024-09-07 03:36:59

由于它是 .docx 文件,因此 Microsoft Word 可能是执行此任务的最佳程序。

我想看看 Word 的[命令行参数]:

看看以下开关:

/q/n/mFilePrintDefault 和 /mFileExit

/q/n 已在上页中解释,/mXxxx 指的是看看谷歌。)

示例:

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

以下页面似乎解释了如何将其转换为PDF。

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.

帥小哥 2024-09-07 03:36:59

您正在寻找的是需要打印的程序的“无头启动”。
我确信 OpenOffice 可以做到这一点。
基本上,您需要启动它并调用一个宏来执行打印。更重要的是,您可以打印为 PDF、HTML 或 Oo 支持的任何其他格式。

这样就无需安装 Microsoft Word 和许可证费用,因为 OpenOffice 是免费的。

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.

小帐篷 2024-09-07 03:36:59

如果

  • 您对宏警告有疑问;
  • 您可以将默认打印机修改为 PDF 打印机或类似打印机;
  • 并且您可以添加或记录宏。

将这样的内容添加到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

然后按照上面的详细说明从命令行调用,例如:

@echo off & setlocal
set ProjectFolder=%USERPROFILE%\Projects
set Project=MyTest
set DocType=docm
start winword "%ProjectFolder:\\=\%%Project%.%DocType%" /q /n /mCmdPrint mFileCloseOrExit

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
能怎样 2024-09-07 03:36:59

如果您只寻找 .docx 无声打印,那么 [aioobe] 答案是最好的。如果您想要在 Windows 上运行的更通用的静默打印程序,请使用 powershell 或 .NET 并使用 print 动词。 http://www .eggheadcafe.com/software/aspnet/30441939/how-to-suppress-printdialog-when-using-print-verb.aspx 提供了一个示例。

希望这有帮助,如果有的话请+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 :)

絕版丫頭 2024-09-07 03:36:59

您可能对 DocTo 感兴趣,它将 Word 文档转换为其他文件格式,包括 pdf 和 XPS,但是确实需要机器上有Word。

例如

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

将 mydocument.docx 作为 pdf 文件输出到 c:\output\mydocument.pdf。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文