How to move to paragraph start

Hi aspose team,
I want to move to paragraph start and insert a book mark over there.

i am trying dbuilder.moveToParagraph but it gives java.lang.NullPointerException

at com.aspose.words.DocumentBuilder.getCurrentStory(DocumentBuilder.java: 1840)
at com.aspose.words.DocumentBuilder.moveToParagraph(DocumentBuilder.java: 343)

or is there any other way?
Please help me out…
Thanks…

Hi

Thanks for your request. Yes, you are right, you should use moveToParagraph method in this case. Could you please attach your document and provide me a simple code, which will allow me to reproduce the problem on my side? I will check the issue and provide you more information.
Best regards.

Hi
Attaching a document

NodeCollection sectionParas = doc.getChildNodes(NodeType.PARAGRAPH, true);
Map map = new HashMap();
int paraSequence = -1;
for (Paragraph para: sectionParas)
{
    paraSequence++;
    map.put(para, paraSequence);
}
for (Paragraph sectionPara: sectionParas)
{
    dbuilder.moveToParagraph(map.get(sectionPara), 0);
}

Please reply
Thanks in advance

Hi

Thank you for additional information. Your code works fine on my side. Also, please try using the following code:

Document doc = new Document("C:\\Temp\\finalWordDoc.doc");
DocumentBuilder dbuilder = new DocumentBuilder(doc);
for (Section section: doc.getSections())
{
    // Move DocumentBuilder cursor into the current section.
    dbuilder.moveToSection(doc.getSections().indexOf(section));
    NodeCollection <Paragraph> sectionParas = section.getChildNodes(NodeType.PARAGRAPH, true);
    for (Paragraph par: sectionParas)
    {
        // Move cursor to the beginning of the current paragraph.
        dbuilder.moveToParagraph(sectionParas.indexOf(par), 0);
        // Insert some text to make sure our code works correct.
        dbuilder.write("[START]");
    }
}
// Save output document.
doc.save("C:\\Temp\\out.doc");

Best regards.