Class PageBreak

  • A PageBreak is an element representing a page break within a document.

  • A PageBreak can be contained within a ListItem or Paragraph, unless they are within certain other document structures like Tables or Headers.

  • A PageBreak cannot contain any other elements.

  • The PageBreak element has various methods available, including copying itself, retrieving and setting attributes, navigating siblings and parent, getting its type, checking if it's at the document end, and removing itself from its parent.

PageBreak

An element representing a page break. A PageBreak can be contained within a ListItem or Paragraph , unless the ListItem or Paragraph is within a Table , HeaderSection , FooterSection , or FootnoteSection . A PageBreak cannot itself contain any other element. For more information on document structure, see the guide to extending Google Docs.

Methods

MethodReturn typeBrief description
copy() PageBreak Returns a detached, deep copy of the current element.
getAttributes() ObjectRetrieves the element's attributes.
getNextSibling() Element Retrieves the element's next sibling element.
getParent() ContainerElement Retrieves the element's parent element.
getPreviousSibling() Element Retrieves the element's previous sibling element.
getType() ElementType Retrieves the element's ElementType .
isAtDocumentEnd() BooleanDetermines whether the element is at the end of the Document .
removeFromParent() PageBreak Removes the element from its parent.
setAttributes(attributes) PageBreak Sets the element's attributes.

Detailed documentation

copy()

Returns a detached, deep copy of the current element.

Any child elements present in the element are also copied. The new element doesn't have a parent.

Return

PageBreak — The new copy.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getAttributes()

Retrieves the element's attributes.

The result is an object containing a property for each valid element attribute where each property name corresponds to an item in the DocumentApp.Attribute enumeration.

constdoc=DocumentApp.getActiveDocument();
constdocumentTab=doc.getActiveTab().asDocumentTab();
constbody=documentTab.getBody();
// Append a styled paragraph.
constpar=body.appendParagraph('A bold, italicized paragraph.');
par.setBold(true);
par.setItalic(true);
// Retrieve the paragraph's attributes.
constatts=par.getAttributes();
// Log the paragraph attributes.
for(constattinatts){
Logger.log(`${att}:${atts[att]}`);
}

Return

Object — The element's attributes.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getNextSibling()

Retrieves the element's next sibling element.

The next sibling has the same parent and follows the current element.

Return

Element — The next sibling element.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getParent()

Retrieves the element's parent element.

The parent element contains the current element.

Return

ContainerElement — The parent element.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getPreviousSibling()

Retrieves the element's previous sibling element.

The previous sibling has the same parent and precedes the current element.

Return

Element — The previous sibling element.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getType()

Retrieves the element's ElementType .

Use getType() to determine the exact type of a given element.

constdoc=DocumentApp.getActiveDocument();
constdocumentTab=doc.getActiveTab().asDocumentTab();
constbody=documentTab.getBody();
// Obtain the first element in the active tab's body.
constfirstChild=body.getChild(0);
// Use getType() to determine the element's type.
if(firstChild.getType()===DocumentApp.ElementType.PARAGRAPH){
Logger.log('The first element is a paragraph.');
}else{
Logger.log('The first element is not a paragraph.');
}

Return

ElementType — The element type.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

isAtDocumentEnd()

Determines whether the element is at the end of the Document .

Return

Boolean — Whether the element is at the end of the tab.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

removeFromParent()

Removes the element from its parent.

constdoc=DocumentApp.getActiveDocument();
constdocumentTab=doc.getActiveTab().asDocumentTab();
constbody=documentTab.getBody();
// Remove all images in the active tab's body.
constimgs=body.getImages();
for(leti=0;i < imgs.length;i++){
imgs[i].removeFromParent();
}

Return

PageBreak — The removed element.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

setAttributes(attributes)

Sets the element's attributes.

The specified attributes parameter must be an object where each property name is an item in the DocumentApp.Attribute enumeration and each property value is the new value to be applied.

constdoc=DocumentApp.getActiveDocument();
constdocumentTab=doc.getActiveTab().asDocumentTab();
constbody=documentTab.getBody();
// Define a custom paragraph style.
conststyle={};
style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT]=
DocumentApp.HorizontalAlignment.RIGHT;
style[DocumentApp.Attribute.FONT_FAMILY]='Calibri';
style[DocumentApp.Attribute.FONT_SIZE]=18;
style[DocumentApp.Attribute.BOLD]=true;
// Append a plain paragraph.
constpar=body.appendParagraph('A paragraph with custom style.');
// Apply the custom style.
par.setAttributes(style);

Parameters

NameTypeDescription
attributesObjectThe element's attributes.

Return

PageBreak — The current element.

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024年12月02日 UTC.