在vb.net中打印word文档

时间:2013-01-03 17:00:10

标签: vb.net

我需要从vb.net打印word.activedocument。 我可以用 document.printout()。来做到这一点,但我需要将文件打印到打印机的特定托盘。 所以现在我正在使用 printdocument.print()这个命令行我可以定义要打印的特定pagesorce,但我不知道如何将我的word文档转换或分配给这个printdocument.print ??? 如果我的问题令人困惑,这是我的代码

Dim oWord As Word.Application = Globals.ThisAddIn.Application         Dim app As Word.Document = oWord.ActiveDocument         Dim objDataTypeMetafile As New Object         objDataTypeMetafile = Word.WdPasteDataType.wdPasteMetafilePicture         'oWord.Visible = True         Dim num_copies As String = tb_num_copies.Text         'oWord.PrintOut(份数:= num_copies,PrintToFile:= False)

    Dim prtdoc As New PrintDocument
    Dim strDefaultPrinter As String = prtdoc.PrinterSettings.PrinterName
    Dim strPrinter As String
    For Each strPrinter In PrinterSettings.InstalledPrinters
        com_printer.Items.Add(strPrinter)

        If strPrinter = strDefaultPrinter Then
            com_printer.SelectedIndex = com_printer.Items.IndexOf(strPrinter)
        End If

        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

                printDoc.Print()

                RemoveHandler printDoc.PrintPage, AddressOf Me.PrintPageHandler

            End If

        Next

    Next strPrinter
    oWord = Nothing

End Sub

Private Sub PrintPageHandler(ByVal sender As Object,ByVal args As Printing.PrintPageEventArgs) ?????????????????? 结束子

0 个答案:

没有答案