How to screenshot a website/URL using C# in .NET Framework

Cloudmersive
1 min readSep 10, 2019

--

Screenshotting websites, while incredibly useful, can be a proper pain. Let’s look today at how to avoid the hassle of setting this up from scratch without using potentially expensive URL screenshotting services. Skipping further ado, let’s jump in.

First step, install our API client using NuGet via the Package Manager console.

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 1.3.4

Then, simply call ConvertWebUrlToScreenshot and provide it with a desired URL, desired dimensions, and additional load time if necessary.

using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;
namespace Example
{
public class ConvertWebUrlToScreenshotExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");
var apiInstance = new ConvertWebApi();
var input = new ScreenshotRequest(); // ScreenshotRequest | Screenshot request parameters
try
{
// Take screenshot of URL
byte[] result = apiInstance.ConvertWebUrlToScreenshot(input);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling ConvertWebApi.ConvertWebUrlToScreenshot: " + e.Message );
}
}
}
}

And that’s all there is to it! Here is an example input:

{
"Url": "google.com",
"ExtraLoadingWait": 0,
"ScreenshotWidth": 500,
"ScreenshotHeight": 500
}

And the corresponding output:

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet