使用 google 脚本从 google 文档中的数组创建(绘制)条形码图像

Create (draw) barcode image from array in google doc using google script

我需要生成条形码图像并将其粘贴到 google 文档中。我发现了如何使用 google 脚本创建一个代表它的 js 数组。但是不知道如何从这个数组创建图像并将其粘贴到 google 文档中。虽然在简单的网页中创建 SVG 图像很容易。

你能帮帮我吗?

如果您可以获得类似 jQuery 插件的东西来使用新的 iFrame HTML 服务,那么您可以在 HTML 中创建条形码,然后将图像保存到图像文件。然后将文件作为 blob。

如果新的 iFrame HTML 服务接受一个插件,并允许 Canvas 标签,它可以那样工作。

我不知道有什么方法可以自己编写代码 JavaScript 来制作条形码。我想你会想先看看互联网上有什么可用的东西。

您问的是一个非常宽泛的问题,需要类似教程的内容才能提供答案。

插入原始发帖人图片的代码:

function insertImage() {
  var baseUrl = canvas.toDataURL("image/png");
  var resp = UrlFetchApp.fetch(baseUrl);

  doc.getChild(0).asParagraph().appendInlineImage(resp.getBlob());
};

原始通用函数:

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
}

您已接受答案,但作为替代方案,我很想将条形码生成交给已发布的 API。有几个。

例如http://www.scandit.com/2012/12/11/create-your-own-barcodes-with-scandits-new-barcode-generator/

原因是除了责任警告之外,还有一个按结果维护的实施测试。不评判你的能力,只考虑好的练习。