roma
roma

Reputation: 1580

App script get first page of google document

I'm trying to create a new document consisting of first pages of other documents.

The problem I'm encountering is that I don't see a way to filter source document elements to only ones that start and end on first page.

This is the code that shows types of all highest level elements of document. Is there any way to filter them, so only ones of first page are included?

  var body = doc.getBody();
  for(var i = 0; i < body.getNumChildren();i++){
    var child = parent.getChild(i);
    Logger.log(child.getType());
  }

I cannot rely on a fact that first page ends with page break, if it is, task is easy.

Upvotes: 2

Views: 1105

Answers (1)

Iamblichus
Iamblichus

Reputation: 19339

There is not an easy way to do what you are trying to accomplish. There is actually an open issue related to this. A page break, or any other marker to look up for, would actually be one of the best workarounds for this.

Another way would be to get the attributes of each element, like font size, spacing, etc., to know how much height each element takes, and compare it to the height of the page, but this is not trivial.

Upvotes: 1

Related Questions