Convert HTML to Image

Posted on 2006-05-13
Last Modified: 2008-02-01

Can anybody give me an example or point me in the direction of a tutorial which shows me code to convert HTML code into an Image of that renedered code, i.e. a web page

Thanks in advance

Question by:REA_ANDREW
    LVL 11

    Expert Comment

    that is not so easy as expected.
    you have to possibilities:
    1. you can make a screenshot from the visible area(the webbrowsers cliprectangle), then you have to scroll by code down to teh next page and grab another screenshot. do it as often as you need until you reached the bottom. at least, you will have to put all that screenshots together.
    the page down message can be send like this:
    SendKeys.Send("{PGDN}"); will have to go through the htmldocument object and render all of its htmlelements by hand in a new graphicsobject of a bitmap.
    the initial size of that bitmap has to be
    LVL 20

    Author Comment

    have you got any code that could get me on my way with this. I particular this part

    "render all of its htmlelements by hand in a new graphicsobject of a bitmap"


    LVL 11

    Accepted Solution

    no sorry, never had a need for that.
    but for accessing all the elements, i could give you an example of a previous answer at :
    that is an example for net 1.1 using the activex web control.
    you woud have to check in the ProcessNode method each type like button, text etc and render that object to your graphic object.

    private void ProcessNode(mshtml.IHTMLDOMNode node)
      if (node is mshtml.IHTMLButtonElement)
          //Do drawing for a button in your graphic object

      if ((node.childNodes as mshtml.IHTMLDOMChildrenCollection).length == 0)
      foreach (mshtml.IHTMLDOMNode childNode in (node.childNodes as mshtml.IHTMLDOMChildrenCollection))

    but i think you will go better with option 1, because its less work and much easier.
    here is a comercial one, dont know, if that would be an option for you:

    another approach could be using the printing option and use the microsoft office document image writer as printer and setup the device to write into a tif format. but then you will get several images of a page.


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    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