计算点网,C#和Syncfusion.DocIO.Net.Core程序包中docs文件中的页面数

问题描述

我有一个.net Core 3.1 webapi。 我想获取文档和doc文件中的页面数。 我正在使用Syncfusion.DocIO.Net.Core包对docs / doc文件执行操作。但是它不提供更新文件状态并仅显示PageCount的功能document.BuiltinDocumentProperties.PageCount; 这不是通过文件更新的。有人可以建议我如何算术吗?

解决方法

感谢您的更新。

从给定的详细信息中,我们发现您的要求是获取Word文档中的页数。您可以使用DocIO从文档的BuiltInProperties获取页数,如下所示。使用Microsoft Word应用程序创建文档时,它会显示文档中的页数,并且如果我们使用DoIO处理文档,它仍会返回相同的页数。

 int count = document.BuiltinDocumentProperties.PageCount;

如果要获取页数,请在使用DocIO处理Word文档后,建议将Word文档转换为PDF,然后按如下所示检索页数。

 WordDocument wordDocument = new WordDocument(fileStream,FormatType.Docx);
 DocIORenderer render = new DocIORenderer();
 //Sets Chart rendering Options.
 render.Settings.ChartRenderingOptions.ImageFormat = ExportImageFormat.Jpeg;
 //Converts Word document into PDF document
 PdfDocument pdfDocument = render.ConvertToPDF(wordDocument);
 int pageCount = pdfDocument.PageCount;

由于Word文档是一种流程文档,其中的内容将不会逐页保留;取而代之的是,内容将逐节依次保留。每个部分都可以根据其内容(如表格,文本,图像等)扩展到各个页面。

Essential DocIO是一个非UI组件,它提供了完善的文档对象模型来处理Word文档内容。因此,使用DocIO直接从Word文档中获取页数是不可行的。

我们已经准备了示例应用程序,可以从word文档中获取页数,可以从下面的链接中下载它。 https://www.syncfusion.com/downloads/support/directtrac/general/ze/GetPageCount16494613

如果您还有其他疑问,请告诉我们。

此致

Manikandan Ravichandran