I have a simple little apps script that refreshes our dynamic logo on request. The problem is I can't target the header if the designer checks "Different first page header/footer" checkbox. Is there away to target the different header if it's checked?
Here is the code I'm currently using:
function onOpen() {
DocumentApp.getUi().createMenu('Branding')
.addItem('Update Branding', 'updateLogo')
.addToUi();
}
function updateLogo() {
var doc = DocumentApp.getActiveDocument();
var header = doc.getHeader();
if (header) {
var images = header.getImages();
var logoWidth = 250;
if (images.length > 0) {
var image = images[0];
logoWidth = image.getWidth(); // pixels
image.removeFromParent();
}
var freshLogo = UrlFetchApp.fetch("http://example.com/logo.jpg").getBlob();
var newImage = header.insertImage(0, freshLogo);
var logoRatio = newImage.getHeight() / newImage.getWidth();
newImage.setWidth(logoWidth);
newImage.setHeight(newImage.getWidth() * logoRatio);
}
}