Link Search Menu Expand Document

Google Apps Script: HTML/CSS to Image

Generate a png, jpg or webp images with Google Apps Script.

Live demo Get an API Key

Table of contents

Generate an image with Google Apps Script

With Google Apps Script, you can build add-ons for Google. It is based on JavaScript, but includes built in functions that you’ll need to use to work with the HTML/CSS to Image API.

Our documented JavaScript examples won’t work with GAS. You can make use of the built in UrlFetchApp to generate images with the API.

Example code

This shows you how to authenticate with the API and pass parameters in a POST request. This is passing html/css parameters to the API. You can adapt this sample to pass any parameters or work with any of our endpoints.

var formData = {
  'html': 'Test',
  'css': 'test',

var options = {
  'method' : 'post',
  'payload' : formData
// Replace username with your User ID and password with your API Key
options.headers = {"Authorization": "Basic " + Utilities.base64Encode(username + ":" + password)};
UrlFetchApp.fetch("", options);

Need help?

We’re always looking to improve this documentation. Please send us an email: We respond fast.

Back to top

Built with extensive integration tests and serious care for developer happiness.
© 2018-2020 Code Happy, LLC.

Page last modified: Mar 30 2022 at 02:56 PM.

Edit this page on GitHub.