How to read bookmarks that are outside of a paragraph with Apache POI XWPF

354 views Asked by At

Sometimes, when defining a bookmark in a .docx file (using Word 2016 in this case), the bookmark start tag (<w:bookmarkStart>) is placed by MS Word before the start of the paragraph. Unzipping the .docx file reveals the following:

<w:bookmarkStart w:id="38" w:name="MyBookmark"/><w:p w14:paraId="1B2F3A46" ...>...
<w:bookmarkEnd w:id="38"/></w:p>

Such a bookmark is not listed by iterating in any of the paragraphs bookmarkStart elements, so that the following code will not list this bookmark:

XWPFDocument document = ...
for (XWPFParagraph paragraph : document.getParagraphs())
{
    for(CTBookmark bookmark : paragraph.getCTP().getBookmarkStartList())
        System.out.println(bookmark.getName());
    {
}

Question is how to discover that sort of bookmark that is placed outside of a paragraph?

0

There are 0 answers