Print multiple files with a WebBrowser Control

854 views Asked by At

I would like to print more than 1 html file, and if it possible, for more than different number of time for each file. I saw MSDN tutorial https://msdn.microsoft.com/en-us/library/b0wes9a3(v=vs.85).aspx and tried to modify it:

// Add an event handler that prints the document after it loads.
        webBrowserForPrinting.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler((sender, e) => PrintDocument(sender, e, file1copies));

        // Set the Url property to load the document.
        webBrowserForPrinting.Url = new Uri(args[1]);

        webBrowserForPrinting.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler((sender, e) => PrintDocument(sender, e, file2copies));
        webBrowserForPrinting.Url = new Uri(args[3]);

and my method:

 private void PrintDocument(object sender, WebBrowserDocumentCompletedEventArgs e, int copies) {
        if (webBrowserForPrinting.ReadyState != WebBrowserReadyState.Complete || webBrowserForPrinting.Url.Equals("about:blank"))
            return;
        try
        {

            for (int i = 0; i < copies; i++) {
                ((WebBrowser)sender).Print();
                Console.WriteLine("Printing...");
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

i only prints the last url every time how can i make it work?

0

There are 0 answers