简体   繁体   English

如何使用 Apps 脚本在 Google Docs 中对齐附加图像

[英]How align an appended image in Google Docs using Apps Script

This script gets a value from an html element and appends it into a gdocs as a textappendText() and a QR code codeappendInlineImage() incrementally.该脚本从 html 元素获取一个值,并将其作为 textappendText() 和二维码 codeappendInlineImage() 增量附加到 gdocs 中。 It does the job so far.到目前为止,它完成了这项工作。

Now I've been trying to align the text and the image in the destination gDocs automatically, but I can't get the syntax right.现在我一直在尝试自动对齐目标 gDocs 中的文本和图像,但我无法获得正确的语法。

I've included an image of my current results and expected results.我已经包含了我当前结果和预期结果的图像。 示例图像

This is my script so far.到目前为止,这是我的脚本。

function createQRCodeSingleItem(fieldData) {
var doc = DocumentApp.openById('1NRSSD_gdfgdfgergdfgdfgdf');
var body = doc.getBody();
var qrCode = fieldData.productId.toString();

 //Logger.log(qrCode)

var url = "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=" + qrCode
var resp = UrlFetchApp.fetch(url); // Get the image of QR code
body.getChild(0).asParagraph().appendText(qrCode);// QR Code referencence number
body.getChild(0).asParagraph().appendInlineImage(resp.getBlob());// OR code
var msg = 'Item INCLUIDO com sucesso!'
    Logger.log(msg);
      return msg;

 }

Take a look at this example doc .看看这个示例文档

You can align the image using the addPositionedImage() for the paragraph in question.您可以使用相关addPositionedImage()对齐图像。

 function createQRCodeSingleItem() {
  var doc = DocumentApp.getActiveDocument();
  var body = doc.getBody();
  var qrCode = '990';  // sample qrCode

  var url = "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=" + qrCode
  var resp = UrlFetchApp.fetch(url); // Get the image of QR code
  // Get or create your desired paragraph
  var paragraph = body.appendParagraph(qrCode).setAlignment(DocumentApp.HorizontalAlignment.LEFT);
  // add positioned image with offsets... Figure out your optimal offset points values
  paragraph.addPositionedImage(resp.getBlob()).setTopOffset(-50).setLeftOffset(75);
}

Here is the Apps Script这是应用程序脚本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM