Aspose.Words如何获取指定页码的orientation

我在把列表的内容遍历放入同一个word时,设置了页面横纵向

        DocumentBuilder docBuilder = new DocumentBuilder(doc);
        for (int i = 0; i < qrcodeDTOList.size(); i++) {
            QrcodeDTO dto = qrcodeDTOList.get(i);
            docBuilder.getPageSetup().setHeaderDistance(0);
            Section section;
            if (i == 0) {
                section = doc.getFirstSection();
            } else {
                section = new Section(doc);
                doc.appendChild(section);
                docBuilder.moveToSection(section.getDocument().indexOf(section));
            }
            // 设置横纵向
            PageSetup pageSetup = docBuilder.getPageSetup();
            int orientation = "row".equalsIgnoreCase(dto.getNextPageOrient()) ? Orientation.LANDSCAPE : Orientation.PORTRAIT;
            pageSetup.setOrientation(orientation);
            docBuilder.getPageSetup().setPaperSize(PaperSize.A4);
            docBuilder.insertHtml(dto.getHtml());
            docBuilder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
        }

而我在读取书签时,想要得到书签所在页 横纵向的信息

BookmarkCollection bookmarks = doc.getRange().getBookmarks();
    if (doc.getRange().getBookmarks() != null && bookmarks.getCount() != 0) {
        LayoutCollector layoutCollector = new LayoutCollector(doc);
        LayoutEnumerator enumerator = new LayoutEnumerator(doc);
        for (Bookmark bookmark : bookmarks) {
            enumerator.setCurrent(layoutCollector.getEntity(bookmark.getBookmarkStart()));
            // 页码是可以拿到的
            int pageIndex = enumerator.getPageIndex();
            // 但这里可以拿到 orient信息吗?目前没有找到

        }
    }

是否有什么方法?谢谢

@chime, 您可以使用 Node.getAncestor 来获取书签的 Section 。

Orientation orientation = ((Section)bookmark.getBookmarkStart().getAncestor(NodeType.SECTION)).getPageSetup().getOrientation();
1 Like