[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 375
  • Last Modified:

Convert HTML to Image

Hi,

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

Andrew
0
REA_ANDREW
Asked:
REA_ANDREW
  • 2
1 Solution
 
vo1dCommented:
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:
this.webBrowser1.Focus();
SendKeys.Send("{PGDN}");

2.you 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
0
 
REA_ANDREWAuthor Commented:
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"

thanks

Andrew
0
 
vo1dCommented:
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 :
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21823323.html
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)
  {
     return;
  }
  foreach (mshtml.IHTMLDOMNode childNode in (node.childNodes as mshtml.IHTMLDOMChildrenCollection))
  {
    ProcessNode(childNode);
  }
}


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:
http://www.guangmingsoft.net/htmlsnapshot/help.htm

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.

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now