[英]How align an appended image in Google Docs using Apps Script
该脚本从 html 元素获取一个值,并将其作为 textappendText() 和二维码 codeappendInlineImage() 增量附加到 gdocs 中。 到目前为止,它完成了这项工作。
现在我一直在尝试自动对齐目标 gDocs 中的文本和图像,但我无法获得正确的语法。
到目前为止,这是我的脚本。
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;
}
看看这个示例文档。
您可以使用相关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);
}
这是应用程序脚本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.