Printing HTML documents in C#


We have a module in a C# Windows application that prints Images and Plain Text  to the default printer using the PrintDocument class.

We need to extend the functionality to allow printing of HTML files also but are facing a problem. If the HTML file is read as a plain text file, it is sent to the printer as the actual HTML markup with all HTML tags and script on the printed document instead of the rendered view that we get on the browser.

Am looking for any pointers to solve this problem….

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

see the following example for printing. This is a clone for IE in VB.NET

You may want to have a look at IE automation.

By That I mean, in your C# Windows Application, you can use the real IE to display pages and so forth.

What you have to do is to open the IE automation, make it load your html page, and then ask it to print.

All this can be done via C# in a transparent way for the user, thus you don't have to redevelop a full web browser just to print a page.

Just look at IE Automation C# in your favorite Search Engine, you will find lots of usefull bits.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
There is already a similar question to this with an accepted answer:
ashish_me2Author Commented:
Thanx all of you for the valuable inputs.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.