gpt4 book ai didi

java - 我们可以使用 aspose api 来识别节号吗?与页码在java中的doc文件中

转载 作者:行者123 更新时间:2023-12-02 04:32:28 25 4
gpt4 key购买 nike

我想通过 aspose java api 识别 doc 文件中带有页面号的部分。

如果我正在使用 aspose api 创建 doc 文件,并尝试通过页面 no 来识别第 no 部分,但当我浏览任何现有文件时,它不会以正确的方式给出

NodeCollection nodes = doc.getChildNodes(NodeType.ANY, true);
for (Node node : (Iterable<Node>) nodes) {
System.out.println(MessageFormat.format("-> NodeType.{0}:", node.getNodeType()));
System.out.println(MessageFormat.format("\tStarts on page {0}, ends on page {1}, spanning {2} pages.", layoutCollector.getStartPageIndex(node), layoutCollector.getEndPageIndex(node), layoutCollector.getNumPagesSpanned(node)));
}

// We can iterate over the layout entities using a LayoutEnumerator
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());

// The LayoutEnumerator can traverse the collection of layout entities like a tree
// We can also point it to any node's corresponding layout entity like this
layoutEnumerator.setCurrent(layoutCollector.getEntity(doc.getChild(NodeType.PARAGRAPH, 1, true)));
Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
Assert.assertEquals("¶", layoutEnumerator.getText());

我希望在单独的页面上提供单独部分的输出

最佳答案

如果您只需要在新页面上开始新部分,则根本不需要 LayoutEnumerator。您有多种选择从新页面开始竞争。

  1. 分页符 https://apireference.aspose.com/java/words/com.aspose.words/breaktype#PAGE_BREAK
  2. 分节符新页面 https://apireference.aspose.com/java/words/com.aspose.words/breaktype#SECTION_BREAK_NEW_PAGE
  3. 段落的PageBreakBefore属性 https://apireference.aspose.com/java/words/com.aspose.words/paragraphformat#PageBreakBefore

例如,如果每个部分(逻辑部分,不是通过分节符插入的部分)都以标题段落开头,那么您只需更改相应样式的 ParagraphFormat.PageBreakBefore 属性,应用此样式的每个段落将从新页面开始。

希望这有帮助。

关于java - 我们可以使用 aspose api 来识别节号吗?与页码在java中的doc文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56574424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com