Insert page break into google document in insertTe

2019-08-04 01:51发布

问题:

I'm making a document merge with google apps script and I want to guarantee that each new 'page' will be on an actual new page.

I recognize that I could use some sort of for loop and appendParagraph(text).appendPageBreak() but, this could be a 100-200 page merge and it seemed very slow and inefficient.

What I'd like to do is just have one .editAsText().setText(text) and be able to just call it once with a huge string and be done. But, the page break seemed difficult and I didn't want to have to dynamically calculate the needed new lines/etc

Is there a way to insert page breaks into plain text?

回答1:

As Wikipedia shows, there's actually a special escape character (á la \n) for page break.

It's \f and it works perfectly. Adding that puts the next line on a new page.