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

Free Support Forum - aspose.com

Detect line/paragraph breaks in document

I want to detect line/paragraph breaks in a document, is it possible using Aspose.words(Java) to detect line/paragraph breaks and replace them?
PFA document for input.
======== Doc Content =============
This is 1st paragraph.
This is 2nd paragraph.
This is 3rd paragraph.

======= Expected Content ==========
This is 1st paragraph.~Line-Break~
This is 2nd paragraph.~Line-Break~
This is 3rd paragraph.~Line-Break~

test_breaks.zip (8.7 KB)

@saket.malpure

Your documents contains the paragraph break. You can iterate over paragraphs nodes of document and get their text. Please check the following code example. Hope this helps you.

Document document = new Document(MyDir + "test_breaks.docx");
for (Paragraph paragraph : (Iterable<Paragraph>)document.getChildNodes(NodeType.PARAGRAPH, true))
{
    System.out.println(paragraph.getText());
} 

We suggest you please read about Aspose.Words’ document object model from here:
Aspose.Words Document Object Model

@tahir.manzoor thanks for quick response.
I tried the suggested code, actually I want to update an end of all paragraphs with ~line-break~.
But when I try to save the document into html format after updating the end of paragraph, the saved html file is not same as word document, bullet points are getting misplaced.
Looks like an issue, please take a look at it.
PFA input and output file.
Code -

Document doc = new Document("document.docx");
NodeCollection<Paragraph> collection = doc.getChildNodes(NodeType.PARAGRAPH, true);
for (Node node : collection.toArray())
{
    System.out.println(node.getRange().getText());
    node.getRange().replace("&p", "~line-break~&p");
}
doc.save("temp.html", SaveFormat.HTML_FIXED);

input.zip (9.0 KB)
output.zip (635 Bytes)

@saket.malpure

We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-19543. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@saket.malpure

Could you please share your expected output document here for our reference? We will then provide you code example accordingly. Thanks for your cooperation.

The issues you have found earlier (filed as WORDSNET-19543) have been fixed in this Aspose.Words for .NET 19.12 update and this Aspose.Words for Java 19.12 update.