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

Free Support Forum - aspose.com

Positioning cursor to beginning of a paragraph

Given a paragraph, I can position the DocumentBuilder cursor to the end of the paragraph using moveTo(myParagraph). How can I position the cursor to the beginning of the paragraph? I want to insert a BookmarkStart node at the beginning of the paragraph.

I tried myParagraph.getParentSection().indexOf(myParagraph) to get the index of myParagraph. This returned 8. But when I tried moveToParagraph(index, 0), the cursor moved to another location further up in the document. The cursor moved to a cell within a table that was a couple of paragraphs above myParagraph.

Thanks.

Yes, indexOf should not be used here as the document builder uses the index of the flattened collection of all paragraphs in the current section, which are not necessarily the immediate children of the section. For example, Paragraph can be a child of a Cell.

The followoing code can help you in this case:

if (para.getFirstChild() != null)

builder.moveTo(para.getFirstChild());

else

builder.moveTo(para);

Please let me know if it worked for you.

Best regards,

Does the above code move the cursor to the BEGINNING of the paragraph?

Hi Dave,

Yes, this code moves cursor to the beginning of the paragraph. I just answered your question here: <A href="https://forum.aspose.com/t/76021</A></P> <P>Best regards,</P>