使用Google脚本从Google文档中的数组创建(绘制)条形码图像 [英] Create (draw) barcode image from array in google doc using google script

查看:83
本文介绍了使用Google脚本从Google文档中的数组创建(绘制)条形码图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

你能帮我吗?

推荐答案

如果您可以使用类似jQuery插件的功能来与新的iFrame HTML服务一起使用,则可以在HTML中创建条形码,然后将图像保存到图像文件.然后以blob的形式获取文件.

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.

如果新的iFrame HTML服务将接受插件并允许Canvas标签,则可以通过这种方式工作.

If the new iFrame HTML Service will accept a pluggin, and allow a Canvas tag, it could work that way.

我不知道一种编码自己的JavaScript来制作条形码的方法.我想您首先要看看互联网上的可用内容.

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());
};

原始通用函数:

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
}

这篇关于使用Google脚本从Google文档中的数组创建(绘制)条形码图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆