Insert page break

I have a large ODT document with paragraphs containing only the character sequence “--” scattered throughout. I should replace these with a page break. How do I do this?

Here are two files with some dummy text that illustrate how the document should be changed:
pagebreaks1-before.odt (28.2 KB)
pagebreaks2-after.odt (12.6 KB)

Version: 25.2.4.3 (X86_64) / LibreOffice Community
Build ID: 33e196637044ead23f5c3226cde09b47731f7e27
CPU threads: 4; OS: macOS 12.7.6; UI render: Skia/Raster; VCL: osx
Locale: en-GB (en_GB.UTF-8); UI: en-US
Calc: threaded

Addapted for -- in place of line breaks:

You will need to first do a Find&Replace with AltSearch:

  • Find --
  • Replace with \M
  • Replace All

The inserted page breaks may still show the “–”. You can replace these relics with an empty string in the second run.
Without AltSearch it’s complicated. I don’t know a way to do it without a macro.

If you want to do it in one go you can use specialised UserDefinedCode:

Sub replaceSpecialisedWithPageBreaks()
Const defaultFind = "--"
text = ThisComponent.Text
For Each asIfPara In text
 If asIfPara.String=defaultFind Then
  asIfPara.String = ""
  asIfPara.BreakType = 5
 EndIf
Next asIfPara
End Sub

Be sure to understand that no page break created in one of the described ways has an explicitly defined page style.
This means: If you change the page style with the cursor in one of these pages this will afflict all the pages.

1 Like