I have some HTML content that I need to print. For other printing tasks, I've had great success using the PrintDialog class by grabbing a grid out of my resources, setting the grid's DataContext property to a ViewModel, and then passing the grid to the PrintVisual method.
I tried using the above method to print HTML by instantiating a System.Windows.Controls.WebBrowser, calling its NavigateToString method (passing in the HTML I need to print) and then passing the WebBrowser to PrintVisual. All I get is a white box. If I set the content of Window to the WebBrowser and then call PrintVisual, the HTML content shows up correctly on the page, but its size is determined by the size of the Window, not the printed page so it looks odd.
Does anyone know how I could get the above method to work? Anybody have a better way of printing HTML in WPF? I've tried some Html to Xaml converters, but have not been impressed with the results.