Kushal
Kushal

Reputation: 3168

Batch printing document loaded in Browser Control in C# WinForm

Here is what I'm trying to do:

  1. I have a simple form with WebBrowser control on it along with Print (ShowPrintDialog()) and Print Preview (ShowPrintPreviewDialog()) buttons,
  2. On opening of the form, I load an external HTML document.
  3. User prints the document using provided print/print preview buttons.

Now the flow is manual, but is there any way I can automate this by loading series of documents into the browser control and directly send it to printing queue without any user intervention? I'm not sure if its technically a batch printing as I'm not sending file to be printed directly to the print queue. Note that Browser control is in the picture here since printed document is essentially WYSWYG as on Browser control.

Upvotes: 1

Views: 823

Answers (1)

Tobia Zambon
Tobia Zambon

Reputation: 7629

You can simply use the Print() method of WebBrowser if you put it into the DocumentCompleted event:

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    webBrowser1.Print();
}

After the print you can pass to the next page to print:

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    webBrowser1.Print();
    webBrowser1.Navigate(nextPage());
}

The only thing you need now is to make the WebBrowser navigate to the first page (you can set it on the constructor of the form)

Upvotes: 1

Related Questions