locked
Convert Straight HTML to Image RRS feed

  • Question

  • User-1670483513 posted

    I am looking for a great example of how to convert dynamic HTML to an image.

    In 95% of cases, this HTML will be enclosed in <DIV> with a "size:auto".

    I have seen a few examples that contain the browser control but all of them need a width/height specification.

    Basically, what I am looking for is the ability to let my user make part of an HTML document and encapsulate that HTML in an image for later viewing.

    Can anyone help me, please. I'm pretty stuck.

    \

    Thanks for any help.

    Saturday, March 6, 2010 4:30 AM

Answers

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 6, 2010 5:51 AM
  • User915387828 posted

    Hi AF1R,

    http://www.acasystems.com/en/web-thumb-activex/faq-asp-convert-html-to-image.htm

    http://www.guangmingsoft.net/htmltoimage/help.htm

    Also you can use gdi+ to implement it at asp.net.

    http://www.sitepoint.com/article/generating-asp-net-images-fly/

    You can retrieve the content of HTML to stream string via System.Net.WebRequest, and then you can convert String to image.

        private void saveURLToImage(string url)
        {
            if (!string.IsNullOrEmpty(url))
            {
                string content = "";

                System.Net.WebRequest webRequest = WebRequest.Create(url);
                System.Net.WebResponse webResponse = webRequest.GetResponse();
                System.IO.StreamReader sr = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"));
                content = sr.ReadToEnd();
                //save to file
                byte[] b = Convert.FromBase64String(content);           
                System.IO.MemoryStream ms = new System.IO.MemoryStream(b);
                System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
                img.Save(@"c:\pic.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

                img.Dispose();
                ms.Close();
            }
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 11, 2010 12:27 AM

All replies

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 6, 2010 5:51 AM
  • User2080859728 posted

    Hello

    Go here

    http://forums.asp.net/t/1221348.aspx

    Saturday, March 6, 2010 12:15 PM
  • User915387828 posted

    Hi AF1R,

    http://www.acasystems.com/en/web-thumb-activex/faq-asp-convert-html-to-image.htm

    http://www.guangmingsoft.net/htmltoimage/help.htm

    Also you can use gdi+ to implement it at asp.net.

    http://www.sitepoint.com/article/generating-asp-net-images-fly/

    You can retrieve the content of HTML to stream string via System.Net.WebRequest, and then you can convert String to image.

        private void saveURLToImage(string url)
        {
            if (!string.IsNullOrEmpty(url))
            {
                string content = "";

                System.Net.WebRequest webRequest = WebRequest.Create(url);
                System.Net.WebResponse webResponse = webRequest.GetResponse();
                System.IO.StreamReader sr = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"));
                content = sr.ReadToEnd();
                //save to file
                byte[] b = Convert.FromBase64String(content);           
                System.IO.MemoryStream ms = new System.IO.MemoryStream(b);
                System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
                img.Save(@"c:\pic.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

                img.Dispose();
                ms.Close();
            }
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 11, 2010 12:27 AM