I found two possibilities:
1) In my opinion, this is worse. I found a third-party software called "Antena house formatter". You can find it at www.antennahouse.com , but unfortunately neither open source nor free software. This software allows you to convert xml, xsl or xsl-fo data to PDF and other formats. From there you can print it with standard C #. I did not choose this path for some reason: to be connected to third-party software, in my opinion, is not a good solution, although this Antennahouse formatter is pretty nice, reliable and fast software.
2) This is the solution that I have chosen. You can create a simple WebBrowser control and fill it with either a saved html file, or simply fill it with a dynamically created line. Now I am creating a line containing the entire html document to load it into the Webbrowser control:
webBrowser1.Document.OpenNew(true); string strHtml = "<html><head></head><body></body></html>"; webBrowser1.Document.Write(strHtml);
When loading a form, I open a new โtabโ with:
webBrowser1.Navigate("about:blank");
You can either show the Webbrowser control to have a "preview" of the site that is being printed, or just hide it. Finally, when you have uploaded your html file to the control, you can print it using:
webBrowser1.Print();
It will print the document with the default printer. I know using an html file to print such a site that feels something like โhacked,โ but this is the easiest way to find something like that. Especially if you can print very complex Sites with many other things on it.
Nice to know:
- I had to print DIN-A4 sites. I set my content to 670 pixels and it works.
- You print using the Webbrowser control. It will take the printer settings from the locally installed Internet Explorer (or registry, if we want to be exact). If you want to change it, go to your IE> Print> Page Settings ... and set the necessary parameters or just change it in your registry.
Hope this helps someone :)
source share