◆C# / ASP.NET SAMPLE

Convert a URL to an Image

Enter the address of a web page and get a screenshot as a PNG, JPEG or BMP image. Free, no signup. The C# code behind this converter is below.

Url:

Image Format:


Web Page Width:
px

Web Page Height:
px
(leave empty to auto detect)

Rendering Engine:

Free to use, no signup. The images carry a “Demo Version” watermark, which a SelectPdf library license removes. A page that has not loaded within 30 seconds fails.

Do this in your own app

C# / VB.NET

.NET library

Install from NuGet and take a screenshot of a web page in a few lines.

HtmlToImage converter = new HtmlToImage();
System.Drawing.Image image =
    converter.ConvertUrl("https://example.com/");
image.Save("screenshot.png", ImageFormat.Png);
See the .NET library

Free Community Edition

Free for commercial use and includes the HTML to image converter. PDFs are limited to 5 pages.

Get the Community Edition
ANY LANGUAGE

Need a PDF instead? HTML to PDF API

Convert a web page to PDF from any language. Get a free API key: 7-day trial, 200 conversions, no credit card.

curl https://selectpdf.com/api2/convert/ \
  -d "key=YOUR_KEY" \
  -d "url=https://example.com" \
  -o document.pdf
Get a free API key

About this website screenshot tool

This converter loads the web page at the address you enter and saves it as a PNG, JPEG or BMP image, using the same engine as the SelectPdf library for .NET. The default Chromium engine renders HTML5, CSS3 and JavaScript; the converter also offers the older WebKit engines.

The image is as wide as the browser window the page is laid out in, 1,024 pixels by default, and as tall as the page unless you enter a height.

Questions

Enter the page's address in the Url box, choose PNG, JPEG or BMP, and click Convert To Image. The screenshot downloads as soon as the conversion is done.
The whole page: with the height left empty, the image is as tall as the page's content. Enter a height, for example 768, to capture only the top of the page.
Yes. The online converter is free to use and needs no signup. The images carry a “Demo Version” watermark, which a SelectPdf library license removes.
PNG, JPEG or BMP. Choose one in the Image Format list before you convert.
Create an HtmlToImage object, call ConvertUrl with the page's address, and save the image it returns. The complete C# code of this page is below.

C# / ASP.NET code for this converter

Sample code · C#
using ColorCode.Compilation.Languages;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing.Imaging;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SelectPdf.Samples
{
    public partial class convert_url_to_image : System.Web.UI.Page
    {
        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            RenderingEngine renderingEngine =
                (RenderingEngine)Enum.Parse(typeof(RenderingEngine), DdlRenderingEngine.SelectedValue, true);

            // read parameters from the webpage
            string url = TxtUrl.Text;

            string image_format = DdlImageFormat.SelectedValue;
            ImageFormat imageFormat = ImageFormat.Png;
            if (image_format == "jpg")
            {
                imageFormat = ImageFormat.Jpeg;
            }
            else if (image_format == "bmp")
            {
                imageFormat = ImageFormat.Bmp;
            }

            int webPageWidth = 1024;
            try
            {
                webPageWidth = Convert.ToInt32(TxtWidth.Text);
            }
            catch { }

            int webPageHeight = 0;
            try
            {
                webPageHeight = Convert.ToInt32(TxtHeight.Text);
            }
            catch { }

            // instantiate a html to image converter object
            HtmlToImage imgConverter = new HtmlToImage();
            imgConverter.MaxPageLoadTime = Global.MaxPageLoadTime;

            imgConverter.RenderingEngine = renderingEngine;

            // set converter options
            imgConverter.WebPageWidth = webPageWidth;
            imgConverter.WebPageHeight = webPageHeight;

            // create a new image converting an url
            System.Drawing.Image image = imgConverter.ConvertUrl(url);

            // send image to browser
            Response.Clear();
            Response.ClearHeaders();
            Response.AddHeader("Content-Type", "image/" + 
                imageFormat.ToString().ToLower());
            Response.AppendHeader("content-disposition",
                "attachment;filename=\"image." + image_format + "\"");
            image.Save(Response.OutputStream, imageFormat);
            Response.End();
        }
    }
}