Matthew
Matthew

Reputation: 179

PHPWord avoid PageBreak command

I'm writing a huge document in PHPWord that includes headings followed by paragraphs of text. I want to make sure that I don't wind up with a heading at the bottom of a sheet with the corresponding text on top of the next page. Since it's a dynamic document, there's no way to know where those breaks will fall ahead of time.

In CSS, there is an "Avoid Page Break" command. Is there anything similar in PHPWord? I have searched and can't find anything. I'm hoping someone out there has discovered it.

something similar to this...

@media print {
  pre, blockquote {page-break-inside: avoid;}
}

Upvotes: 0

Views: 442

Answers (1)

Matthew
Matthew

Reputation: 179

I figured it out...in case anyone else is running into the same problem, within your paragraphStyle, use the setting:

'keepNext' => true

This engages a word setting that keeps a paragraph with whatever comes immediately after it. So if the paragraph following a heading is forced onto the next page, this will make sure that the heading goes with it.

Upvotes: 2

Related Questions