1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Dynamically generate an image from templated, styled html using google apps script

Discussion in 'Programming/Internet' started by user10355305, Sep 12, 2018.

  1. user10355305

    user10355305 Guest

    I am trying to use a Google Sheets script to generate a new Google forms based on data inside a sheet. However I need to styled some of the questions with some specific CSS. Since I cannot set the styling of question text in a Google form, I was thinking that I could generate the styled HTML and convert that to an image and add the image to the Google form.

    So, I'm able to generate the styled HTML, and I can save the html file and it looks exactly as I want it to. But I can't seem to figure out how to convert that into an image blob that I can set in the form.

    I want to do something like:

    var form = FormApp.create("test");
    var imageItem = form.addImageItem();
    var img = generateImage(page.scenario, page.title);

    function generateImage(scenario, name) {
    var t = HtmlService.createTemplateFromFile('index');
    t.data = scenario;
    var htmlOutput = t.evaluate();
    //do something to generate an image from the HTML
    return htmlOutput;

    This code as-is gives me an error "Blob object must have an image content type for this operation".

    Any thoughts on how to convert the html into an image that can serve as a valid Blobsource? Or maybe there's an html-side solution making use of some javascript library?

    Login To add answer/comment

Share This Page