I need to generate and paste barcode image in a google doc. I've found out how to create a js array, which represents it, using google script. But have no idea how to create and paste an image from this array into google doc. Although it's easy to create an SVG image in a simple web page.
Can you please help me?
If you can get something like a jQuery pluggin to work with the new iFrame HTML service, then you could create the bar code in HTML, then save the image to an image file. Then get the file as a blob.
If the new iFrame HTML Service will accept a pluggin, and allow a Canvas tag, it could work that way.
I don't know of a way to code your own JavaScript to make the bar code. I think you'd want to start with seeing what is available out there on the internet.
You are asking a very broad question, that would require something like a tutorial to provide an answer.
Code to insert image from Original Poster:
function insertImage() {
var baseUrl = canvas.toDataURL("image/png");
var resp = UrlFetchApp.fetch(baseUrl);
doc.getChild(0).asParagraph().appendInlineImage(resp.getBlob());
};
Original Generic function:
function insertImage() {
var Doc = DocumentApp.openById('Your Doc ID here');
var image = DocsList.getFileById('Your Image ID here');
// Use this if the Doc is open and code running is bound to this doc
//var body = DocumentApp.getActiveDocument().getBody();
var body = Doc.getBody();
var whatParagraph = 3; //Insert an image in the fourth paragraph
body.insertImage(image);// 'image' is the image file as blob
//body.appendImage(whatParagraph, image); // Either insert or append can be used
}