Batch Printing

takwirira

Member
Joined
Dec 21, 2007
Messages
23
Programming Experience
Beginner
Hi

Im basically stuck for ideas but I would like to create a program that prints i.e. I have a folder with x amount of .htm files e.g. reports that I would like to batch print. Instead of have to open each one and print in Internet Explorer I'd like to automate this process.

Thanks
 
Thanks so much John, that works excellent, I had to take out the loop since I only want to print 1 copy of each. I have a question though, with the web browser object how can I customise it so that it does not print the headers and footers i.e. (Page 1 of 1, address etc.). In Internet Explorer 7 its possible to remove these before printing. Any ideas on doing this programatically
 
The end result code is as below, could you please help me out as to why its not printing?

It gives an Internet Explorer script error

An error has occured in the script on this page
Line:258
Char:1
Error:'dialogArguments._IE_PrintType' is null or not an object
Code: 0
URL: res://ieframe.dll/preview.dlg

Do you want to continue running scripts on this page etc....

VB.NET:
Public Class Print
    Dim spl As String
    Dim file As String = IO.Path.Combine("c:\invoices\", "222153    .htm")
    Private Sub runPrintJobs()
        Dim t As New Threading.Thread(AddressOf printthread)
        t.IsBackground = True
        t.SetApartmentState(Threading.ApartmentState.STA)
        t.Start()
    End Sub

    Private Sub printthread()
        Dim wb As New WebBrowser
        wb.Navigate(file)
        Do Until wb.ReadyState = WebBrowserReadyState.Complete
            Application.DoEvents()
        Loop
        wb.Print()
        wb.Dispose()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        looper()
    End Sub
    Private Sub looper()

        Dim strFile As String
        Dim strList As String

        strFile = Dir("C:\Invoices\*.*")

        While Len(strFile) > 0
            strList = strList & strFile
            strFile = Dir()
            ListBox1.Items.Add(strList)
            strList = ""
        End While

        Do

            spl = ListBox1.Items.Item(0).ToString
            file = IO.Path.Combine("C:\Invoices\", spl)
            runPrintJobs()
            'remove item
            ListBox1.Items.RemoveAt(0)

        Loop Until ListBox1.Items.Count = 1


    End Sub

End Class
 
Back
Top