我需要将 word 活动文档打印到特定托盘中。例如,如果用户单击按钮字母,则文档应从托盘 2 打印。目前我正在使用这段基本代码
Dim word As Word.Application = Globals.ThisAddIn.Application
Dim pd As New PrintDialog()
pd.PrinterSettings = New PrinterSettings()
If pd.ShowDialog() = DialogResult.OK Then
word.PrintOut()
End If
如果我使用属性 prindocument(),我已经设法完成了一些与此相关的工作。类似的东西
Dim pkSource As Printing.PaperSource Dim printDoc As New PrintDocument ' AddHandler printDoc.PrintPage
printDoc.PrinterSettings.PrinterName = strPrinter
For Each pkSource In printDoc.PrinterSettings.PaperSources
If pkSource.RawKind = "261" Then
printDoc.PrinterSettings.DefaultPageSettings.PaperSource.RawKind = pkSource.RawKind
Dim psize As Printing.PaperSize = printDoc.PrinterSettings.PaperSizes.Item(5)
printDoc.DefaultPageSettings.PaperSize = psize
printDoc.PrinterSettings.PrintRange = PrintRange.AllPages
'AddHandler printDoc.PrintPage, AddressOf Me.PrintDoc_PrintPage
printDoc.PrinterSettings.Copies = num_copies
printDoc.PrinterSettings.Duplex = Duplex.Default
AddHandler printDoc.PrintPage, AddressOf Me.PrintPageHandler
'PrintDocument1 = oWord.ActiveDocument
Try
'PrintDocument1.Print()
printDoc = app
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
'printDoc.Print()
' MsgBox("printed")
RemoveHandler printDoc.PrintPage, AddressOf Me.PrintPageHandler
End If
Next
但我不想使用打印文档,因为我需要打印激活的 Word 文档。