1

我有一份数百页的报告。我需要创建从这个文档中提取每个单独的页面到一个新文档中。我发现使用 INTEROP 可以做到这一点,但是我试图避免在服务器上安装 MS Office。我一直在使用 ASPOSE 进行大部分操作,但似乎不支持此功能。

有没有办法在不安装 MS Office 的情况下将文档的页面分成单独的文件?

4

1 回答 1

2

Aspose.Words 没有页面或行号等布局信息。它维护 DOM。但是我们已经编写了一些实用程序类来实现这种行为。他们将 word 文档分成多个部分,这样每一页就成为一个单独的部分。之后,很容易复制单个页面。

String sourceDoc = dataDir + "source.docx";
String destinationtDoc = dataDir + "destination.docx";

// Initialize the Document instance with source and destination documents
Document doc = new Document(sourceDoc);
Document dstDoc = new Document();

// Remove the blank default page from new document
dstDoc.RemoveAllChildren();
PageNumberFinder finder = new PageNumberFinder(doc);
// Split nodes across pages
finder.SplitNodesAcrossPages(true);
// Get separate page sections
ArrayList pageSections = finder.RetrieveAllNodesOnPages(1, 5, NodeType.Section);
foreach (Section section in pageSections)
    dstDoc.AppendChild(dstDoc.ImportNode(section, true));
dstDoc.LastSection.Body.LastParagraph.Remove();
dstDoc.Save(destinationtDoc);

PageNumberFinder 类可以从这里下载。

PS。我是 Aspose 的开发人员布道师。

于 2013-05-09T06:50:58.593 回答