首页 > 解决方案 > 我们可以使用 aspose api 来识别节号吗?与页码。在java中的doc文件中

问题描述

我想通过 aspose java api 识别 doc 文件中没有页码的部分。

如果我正在使用 aspose api 创建 doc 文件并尝试用 page 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());

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

标签: javadocsectionsaspose.words

解决方案


如果您只需要在新页面上开始新部分,则根本不需要 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 属性,并且应用此样式的每个段落都将从新页面开始。

希望这可以帮助。


推荐阅读