It is also possible to do it with an embedded web browser, note however that since this might be a local file, and also because it is not actually the browser directly and there is no DOM so there is no ready state.
Here is the code for the approach I worked out on a win form web browser control:
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate(@"path\to\file");
}
private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
//Progress Changed fires multiple times, however after the Navigated event it is fired only once,
//and at this point it is ready to print
webBrowser1.ProgressChanged += (o, args) =>
{
webBrowser1.Print();//Note this does not print only brings up the print preview dialog
//Should be on a separate task to ensure the main thread
//can fully initialize the print dialog
Task.Factory.StartNew(() =>
{
Thread.Sleep(1000);//We need to wait before we can send enter
//This assumes that the print preview is still in focus
Action g = () =>
{
SendKeys.SendWait("{ENTER}");
};
this.Invoke(g);
});
};
}