Skiminok
Skiminok

Reputation: 2871

How to get a bounding box for a HTMLAgilityPack DOM element in C#?

My application uses HtmlAgilityPack to download HTML documents and analyze their DOM structure with a lot of XPath queries. Disclaimer: XPath support is extremely important for my purposes, I cannot switch to CSS selectors, for example. This is the main (and, probably, the only) reason why I use HtmlAgilityPack.

I have an HtmlAgilityPack.HtmlNode, chosen from a HTML document with some XPath query. Now I need to implement one additional method: What would be the bounding box coordinates of this element, if it was rendered by some engine? I don't even care which particular engine is used, let it be WebKit, MSIE, Gecko/Firefox etc. I just need a way to:

  1. Render a document in memory on an arbitrarily sized canvas (say, 1900*1200 pixels).
  2. Setup a one-to-one correspondence between a renderer's DOM tree and the HtmlAgilityPack.HtmlDocument that I already have.
  3. Ask a renderer for a bounding box of a particular DOM element (HtmlAgilityPack.HtmlNode) on this canvas.

I already spent half a day looking into various HTML rendering engines for .NET but still haven't found a way to do this. Maybe someone has already solved a similar problem? Thank you for any help.

Upvotes: 2

Views: 945

Answers (1)

Dima Kurilo
Dima Kurilo

Reputation: 2276

You can try to add custom attribute. Then find it in WebBrowser control.
Something like this.

Upvotes: 2

Related Questions