WebBrowser使用PDFCreator以编程方式打印

时间:2018-08-20 14:45:36

标签: vb.net pdf printing .net-3.5 pdf-generation

我正在尝试以编程方式从VB.Net中的WebBrowser打印多个html页面。我制作的程序是一个网络抓取程序,可从货运公司的网站获取有关货运的信息,并为每个货运代码将html页打印为pdf。 我选择了PDFCreator作为打印机,并且设法打印了每个html页面,但是PDFCreator显示了每个要打印的html的对话框窗口。有没有一种方法可以以编程方式选择 文件名 输出路径 ,然后不会向用户询问任何内容而打印?

这是更改默认打印机的子项:

Private Sub SetPrinter(ByVal printerName As String)
    Shell(String.Format("rundll32 printui.dll,PrintUIEntry /y /n ""{0}""", printerName))
End Sub

这是代码打印html的地方:

 Private Function FindShipment(ByVal TrackingUrl As String, ByVal indexShipmentCode As Integer, ByVal shipmentCode as DataTable) As Boolean
    Try
        WebBrowser1.Navigate(TrackingUrl)
        WaitForPageLoad()
        Dim trackingTextBox As HtmlElement = WebBrowser1.Document.All.Item("id_ldv")
        trackingTextBox.InnerText = shipmentCode.Rows(indexShipmentCode).Item(0)
        'shipment code is a DataTable filled with info took from excel file
        WebBrowser1.Document.All("button").InvokeMember("click")
        WaitForPageLoad()
        WebBrowser1.Print()
        Return True
    Catch ex As Exception
        Return False
    End Try
End Function

FindShipment在一个循环内被调用,WebBrowser1.Print()在每个循环中打开一个对话框窗口。

0 个答案:

没有答案