We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Find and replace page break marker in document

Suppose that, in the text of a document, I place a marker text like <!-- page break -->, is there a way to search the text inside a document and replace it with an actual page break?

Thanks.

@mtassinari,

Thanks for your inquiry. Please use Range.Replace method as shown below to get the desired output.

Document doc = new Document(MyDir + "in.txt");
doc.Range.Replace(@"<!-- page break -->", ControlChar.PageBreak, new FindReplaceOptions());
doc.Save(MyDir + "17.10.docx");

That’s C# code right?

In Java it should be something like

document.getRange().replace("<-- {{PAGE BREAK}} -->", ControlChar.PAGE_BREAK, new FindReplaceOptions());

If so, I tried that but it didn’t seem to work… Is the code right?

Nevermind, I found the problem: it was caused by the fact that the marker I used for the page break is an HTML comment, which apparently does not get inserted with the builder.insertHtml method, changing the marker to a plain string solved the issue.

Thanks for you help, it is much appreciated!

@mtassinari,

Thanks for your feedback. It is nice to hear from you that your issue has been solved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.