I'm trying to write a simple script to delete the first page from a Google doc (well, many, many Google docs, but that part I've got figured out already). I haven't had any luck with the .removeFromParent or other commands, but I seem to be able to delete the text using the paragraph.clear() command.
However, the cleared paragraphs leave a page of whitespace (and bullet points) that I would like to get rid of. How can I delete the page completely so the document starts from Page 2?
----------------------------
function deleteFirstPage(target) {
var deletePages = 1;
var paragraph = DocumentApp.openById(target)
.getBody()
.getParagraphs();
var counter = 0;
for (var i = 0; i < paragraph.length; i++) {
for (var j = 0; j < paragraph[i].getNumChildren(); j++){
if (
paragraph[i].getChild(j).getType() == DocumentApp.ElementType.PAGE_BREAK
)
counter++;
}
//paragraph[i].editAsText().setText('');
paragraph[i].clear();
if (counter == deletePages) break;
}
}