【问题标题】:Word Document Print from specific Tray从特定托盘打印 Word 文档
【发布时间】:2014-05-02 21:50:15
【问题描述】:

我需要将 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(),我已经设法完成了一些与此相关的工作。有点像

将 pkSource 调暗为 Printing.PaperSource 将 printDoc 调暗为新的 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 文档。

【问题讨论】:

    标签: vb.net


    【解决方案1】:

    我很确定您不能向 PrintDocument 对象添加内容 - 但它确实公开了您可以在页面级别操作的事件。

    话虽如此,您似乎是在 Word 中工作。为什么不用word object的ActiveDocument来设置托盘(firstPageTray和otherPagesTray)呢?

    【讨论】:

    • 谢谢回复。对不起,我不擅长,如果你可以请给我任何例子,这将非常有帮助,与(firstPageTray 和 otherPagesTray)一起工作......谢谢
    • Dim wd As Word.Application = Globals.ThisAddIn.Application Dim doc As Word.Document = wd.ActiveDocument doc.PageSetup.FirstPageTray = 262 doc.PageSetup.OtherPagesTray = 262 'doc.PrintOut()
    • 应该可以。指针值是长的。有多种方法可以获取托盘 ID(长整数)和托盘名称列表。
    猜你喜欢
    • 1970-01-01
    • 2013-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-18
    • 1970-01-01
    • 1970-01-01
    • 2014-04-11
    相关资源
    最近更新 更多