I would like to replicate in Google Scripts VBA code that I wrote for Word docs. Basically, it "slices" a document into multiple PDF files by searching for tags that I insert into the document. The purpose is to allow choirs using forScore (an app that manages musical scores) to insert previously annotated musical scores at the slice points. That way, during a performance they can page through a musical program in its entirety from start to finish.
This is what I have so far. I know it's sketchy, and it doesn't actually work as is:
enter code here
// Loop through body elements searching for the slice tags
// Slice tag example: #LCH-Introit (Seven Seasonal-God is Ascended)#
// When a slice tag is found a document is created with a subsection of the document
// NOT SURE USING RANGES IS WHAT'S NEEDED
rangeBuilder = doc.newRange();
for (i = 0; i < body.getNumChildren(); i++) {
child = body.getChild(i);
rangeBuilder.addElement(child);
// Logger.log(fName + ": element(" + i + ") type = " + child.getType());
if (child.getType() === DocumentApp.ElementType.PARAGRAPH) {
foundElement = child.findText('#LCH-');
if (foundElement) {
txt = foundElement.getElement().getParent().editAsText().getText();
// Generate PDF file name
count++;
padNum = padDigits(count, 2); // Function I wrote to pad zeroes
pdfName = serviceName + '-' + padNum + ' ' + txt.substr(txt.indexOf('-') + 1, (txt.length - txt.indexOf('-') - 2));
Logger.log(fName + ": pdfName = " + pdfName);
// Create new doc and populate with current Elements
// Here's where I'm stuck.
// There doesn't seem to be a way to reference page numbers in Google Scripts.
// That would make things much easier.
// docTemp = DocumentApp.create(pdfName);
}
}
}