java - 我们可以使用 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());
我希望在单独的页面上提供单独部分的输出
解决方案
如果您只需要在新页面上开始新部分,则根本不需要 LayoutEnumerator。您有几个选项可以从新页面开始竞争。
- 分页符 https://apireference.aspose.com/java/words/com.aspose.words/breaktype#PAGE_BREAK
- 分节符新页面 https://apireference.aspose.com/java/words/com.aspose.words/breaktype#SECTION_BREAK_NEW_PAGE
- 段落的 PageBreakBefore 属性 https://apireference.aspose.com/java/words/com.aspose.words/paragraphformat#PageBreakBefore
例如,如果每个部分(逻辑部分,而不是由分节符插入的部分)以标题段落开头,那么您可以简单地更改相应样式的 ParagraphFormat.PageBreakBefore 属性,并且应用此样式的每个段落都将从新页面开始。
希望这可以帮助。
推荐阅读
- dart - 如何复制另一种按钮样式?
- android-studio - 在最新的 Android Studio 中找不到 R.java
- python - 在张量流中重新分配非变量张量
- xslt-1.0 - using substring-before - 搜索特定字符串,然后提取另一个
- kubernetes - Kubernetes (AKS):将不同服务的多个端口暴露给公共负载均衡器
- python - 使用 pandas 将行值替换为序列值
- excel - 使用 vba 宏从数据透视表中选择字段
- sql - 为sql逗号分隔字符串中的每个单词插入引号并在Function SQL中使用
- c - EXC_BAD_ACCESS 错误
- c++ - “auto x = 矢量”有什么区别
()”和“向量 X”?