Last updated 5 months ago

Converting HTML/CSS to an Image with C#

Example Code

This code creates a WebClient, sets credentials and POSTS the HTML & CSS as values to the API. The response will be json with the URL to the generated image.

using System.Net;
namespace htciExample
class Program
static void Main()
byte[] result;
string html = "<div class='ping'>Pong ✅</div>";
string css = ".ping {padding: 20px; font-family:'sans-serif'; }";
using (var client = new WebClient())
client.Credentials = new NetworkCredential("user_id", "api_key");
result = client.UploadValues(
new System.Collections.Specialized.NameValueCollection()
{ "html", html }, { "css", css }
string resultString = System.Text.Encoding.UTF8.GetString(result);

More examples

For more advanced examples, take a look here.