mercredi 26 septembre 2018

C# - Know the height of HTML content in a console application

I have HTML code something like -

<html>
<body>
<table><tr><td><h1>Heading</h1></td></tr></table>
</body>
</html>

In a specific requirement, I need to know in advance that how much height will this HTML will take to display in fullscreen. So that I keep that much space calculated specifically for that content.

What I thought was to render this code in WebBrowser control, and then take the height.

        this.webBrowser1.Url = new Uri(htmlFilePath);
        //The below code will force the webbrowser control to load the HTML in it.
        while (this.webBrowser1.Document.Body == null)
        {
            Application.DoEvents();
        }
        int height = this.webBrowser1.Document.Body.ScrollRectangle.Height;

But in console application I can't use WebBrowser control. Is there any other way I can accomplish this?




Aucun commentaire:

Enregistrer un commentaire