Printing HTML documents in C#

Posted on 2004-11-03
Last Modified: 2012-06-27

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….

Question by:ashish_me2
    LVL 18

    Expert Comment

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

    Accepted Solution


    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.

    LVL 3

    Expert Comment

    There is already a similar question to this with an accepted answer:

    Author Comment

    Thanx all of you for the valuable inputs.


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    This video discusses moving either the default database or any database to a new volume.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now