Logos
Opened this issue · 0 comments
malaref commented
There is a problem with inserting the logos in their appropriate places. At the time of this writing, trying to open images using the Drive API as well as direct links is buggy and produces blank images.
The following code may serve as a starting point for anyone who wants to fix this issue.
var logo = header.indexOf("Logo");
var imageFile = UrlFetchApp.fetch("http://drive.google.com/uc?export=view&id=" + row[logo].match(/[-\w]{25,}/)[0]);
var logoCell = table.findText("{LOGO}").getElement().getParent().asParagraph();
logoCell.clear();
var image = logoCell.insertInlineImage(0, imageFile);
var ratio = image.getHeight() / image.getWidth();
image.setWidth(logoCell.getParent().asTableCell().getWidth() * 2);
image.setHeight(image.getWidth() * ratio);
var style = {};
style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.CENTER;
logoCell.setAttributes(style);