https://developers.google.com/apps-script/class_documentbodysection#appendImage
I basically open a document and get its DocumentBodySection, I then iterate through the elements, copy them (Element.copy()) to get a deep detached copy and then append the element to another document.
This works well for paragraph and other element types, but when it comes to inline images, I get a broken link in the resulting document.
Anyone got that to work?
Here is a snippet
function appendSection(doc, section) {
for (i=0; i<section.getNumChildren(); i++) {
var el = section.getChild(i);
if (el.getType() == DocumentApp.ElementType.PARAGRAPH)
{
if (el.getNumChildren() != 0) {
var el_child = el.getChild(0);
if (el_child.getType() == DocumentApp.ElementType.INLINE_IMAGE)
{
doc.appendImage(el_child.asInlineImage().copy());
Logger.log("Image");
}
}
doc.appendParagraph(el.copy());
Logger.log("Paragraph");
}
}
return doc
}
Thanks in advance.