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

如何将PDF字节数组转换为可读取文档?可使用DevExpress框架

使用DevExpress处理PDF byte[]数组的方案

场景1:可视化查看PDF内容

如果需要在WinForms/WPF界面中直接查看PDF,可使用DevExpress的PDF Viewer控件加载byte[]:

WinForms示例

// 假设已在窗体中添加PdfViewer控件实例pdfViewer1
byte[] pdfBytes = /* 你的PDF字节数组 */;

using (MemoryStream ms = new MemoryStream(pdfBytes))
{
    pdfViewer1.LoadDocument(ms);
}

WPF示例

// 假设已添加PdfViewerControl实例pdfViewerControl
byte[] pdfBytes = /* 你的PDF字节数组 */;

using (MemoryStream ms = new MemoryStream(pdfBytes))
{
    pdfViewerControl.DocumentSource = ms;
}

场景2:提取PDF文本内容

如果仅需读取PDF中的文本,无需可视化,可使用PdfDocumentProcessor类:

byte[] pdfBytes = /* 你的PDF字节数组 */;
string extractedText = string.Empty;

using (MemoryStream ms = new MemoryStream(pdfBytes))
{
    using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
    {
        processor.LoadDocument(ms);
        extractedText = processor.TextContent.ToString();
    }
}

// extractedText即为PDF中的文本内容

注意事项

  • 确保项目已引用DevExpress.Docs、DevExpress.Pdf.Core、DevExpress.Pdf.Viewer相关程序集;
  • ASP.NET场景下,可将byte[]直接输出到响应流,让浏览器打开:
byte[] pdfBytes = /* 你的PDF字节数组 */;
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline; filename=document.pdf");
Response.BinaryWrite(pdfBytes);
Response.End();

内容的提问来源于stack exchange,提问作者Gonçalo Bastos

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 20:01:06