I am trying to use a Google Sheets script to generate a new Google form based on data inside a sheet. However I need to style 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);
imageItem.setImage(img);
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? FYI I'm trying to do this as a "batch" for many images, so I don't want to have to wait for user action as part of this.