I'm basically doing a mail-merge (replacing Total: $ {total_amount}
for Total: $ 20.00
) in a Google Docs document with Google App Script.
However, I want a preview
option, where I show a modal dialog or something, and then I append to it a copy of the Body
of the actual document. That way I can replace all the variables and keeping the original format (bold, italics, etc).
I already have an implementation that loads the current document as HTML exported and appends it to the dialog.
html = getGoogleDocumentAsHTML();
replaced = replace(html);
output = HtmlService.createHtmlOutput(replaced)
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(700)
.setHeight(500);
DocumentApp.getUi().showModalDialog(output, 'Preview');
/*
* @see http://stackoverflow.com/questions/14663852/get-google-document-as-html#answer-28503601
*/
function getGoogleDocumentAsHTML(){ ...
But with this approach I am unable to show the pages, so that the user knows the paragraphs that fits on each page, layout, etc.
Is there any way to get a copy of the Document
's Body
to do this, or a similar approach?