【发布时间】:2015-05-01 14:42:13
【问题描述】:
我有一个应用程序可以监控新文档的网络位置。 它们可以是 word 文档、PDF 文件、电子表格等。
检测到文档后,会将其复制到 c:\Temp 内的本地文件夹中。
我需要将文档在复制后发送到指定的(非默认)打印机。
有人对我如何实现这一点有任何想法吗?
谢谢!!
【问题讨论】:
标签: vb.net visual-studio-2012 printing document
我有一个应用程序可以监控新文档的网络位置。 它们可以是 word 文档、PDF 文件、电子表格等。
检测到文档后,会将其复制到 c:\Temp 内的本地文件夹中。
我需要将文档在复制后发送到指定的(非默认)打印机。
有人对我如何实现这一点有任何想法吗?
谢谢!!
【问题讨论】:
标签: vb.net visual-studio-2012 printing document
您可能需要创建多种功能来打印文档。就像使用LPR 打印 PDF 或 PostScript,Microsoft.Office.Interop 用于 Word 和 Excel 文档等等...
如果是我,我会使用System.IO.Path.GetExtension(filename) 来确定文件类型,然后调用最合适的函数……或者如果未处理格式,则记录文件不可打印。
Microsoft.Office.Interop Microsoft.Office.Interop.Excel,您可以在Workbook 或Worksheet 上调用PrintOutEx 方法并指定要使用的打印机。 使用Microsoft.Office.Interop.Word,您可以设置Application 的ActivePrinter 属性,然后在PrintOut 上使用PrintOut 方法。
见:
https://msdn.microsoft.com/en-us/library/microsoft.office.interop.word._application.activeprinter.aspx
和
https://msdn.microsoft.com/en-us/library/microsoft.office.interop.word._document.printout.aspx
'Set the IP address of the printer to use.
If printer1 Then
printserver = printer1Address
ElseIf printer2 Then
printserver = printer2Address
ElseIf printer3 Then
printserver = printer3Address
End If
'Use LPR to print the file.
Dim lprProcess As New Process()
With lprProcess.StartInfo
.UseShellExecute = False
.FileName = "CMD"
.Arguments = "/c LPR -s " & printserver & " -P P3 " & myNewFileName
End With
lprProcess.Start()
在 Windows 7 及更高版本中默认不包含 LPR,但打开它是一件轻而易举的事。请参阅http://campus.mst.edu/cis/desktop/documentation/pc/win7_x64/lpr_printer/install.htm 上的步骤 1-3
【讨论】: