You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在C#中使用Active Report 10将Doc/Word文件转为PDF?

ActiveReports 10 中Doc转PDF的可用命名空间及类

GrapeCity.Documents.Word.Layout是GcWord库的命名空间,这个库并不属于ActiveReports 10的内置组件,所以直接引用会报错。ActiveReports 10有自己的一套文档转PDF的机制,相关的命名空间和类如下:

核心组件

  • GrapeCity.ActiveReports.Export.Pdf.Section 命名空间

    • PdfExport 类:这是AR10里负责将文档导出为PDF的核心类,既支持导出Section报表,也能处理加载后的Word文档。
    • 核心方法:Export(Document document, Stream stream) —— 把Document对象导出为PDF流。
  • GrapeCity.ActiveReports.Document 命名空间

    • Document 类:代表AR10的文档实例,需要先把本地Doc文件加载到这个对象里,才能进行PDF导出。
    • 核心方法:Load(string fileName) —— 加载指定路径的Doc文件。

简单实现示例

using GrapeCity.ActiveReports.Document;
using GrapeCity.ActiveReports.Export.Pdf.Section;
using System.IO;

// 加载Doc文件到Document对象
Document arDoc = new Document();
arDoc.Load(@"C:\your-input-file.doc");

// 初始化PDF导出器
PdfExport pdfExporter = new PdfExport();

// 导出到目标PDF文件
using (Stream outputStream = new FileStream(@"C:\your-output-file.pdf", FileMode.Create))
{
    pdfExporter.Export(arDoc, outputStream);
}

额外说明

  • AR10的Doc文件处理基于自身解析引擎,仅对旧版.doc格式支持较好,对.docx格式的兼容性有限。
  • 如果需要处理复杂的.docx文档,AR10无法满足,得升级到包含GcWord组件的新版本ActiveReports。

内容的提问来源于stack exchange,提问作者Abhijeet Kumar Jha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 14:30:58