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

Free Support Forum - aspose.com

是否有获取docx文件中书签的坐标或者位置等方法

我通过下面的代码获取到了书签集合,但是书签中没有位置等属性

    com.aspose.words.Document document = new com.aspose.words.Document("C:\\Users\\Administrator\\Downloads\\docx.docx");
    BookmarkCollection bookmarks = document.getRange().getBookmarks();

@humanhuman, 您可以使用 LayoutCollector 获取放置书签的页码,getNextSiblinggetPreviousSibling 属性获取前后节点。 例如看下面的代码:

Document doc = new Document("in.docx");
LayoutCollector collector = new LayoutCollector(doc);
for (Bookmark bk : doc.getRange().getBookmarks())
{
    System.out.println("Bookmark: " + bk.getName());
    System.out.println("Page: " + collector.getStartPageIndex(bk.getBookmarkStart()));

    Node previousSibling = bk.getBookmarkStart().getPreviousSibling();
    String previousSiblingText = previousSibling != null ? previousSibling.toString(SaveFormat.TEXT).trim() : "";
    System.out.println("Preceding text: '" + previousSiblingText + "'");

    Node nextSibling = bk.getBookmarkEnd().getNextSibling();
    String nextSiblingText = nextSibling != null ? nextSibling.toString(SaveFormat.TEXT).trim() : "";
    System.out.println("Following text: '" + nextSiblingText + "'");
    System.out.println("---------------------------");
}

in.docx (15.0 KB)

请参阅 Aspose.Words Object Model 了解更多信息:
https://docs.aspose.com/words/net/aspose-words-document-object-model/

您可以使用 DocumentExplorer 来探索文档中的节点: