【问题标题】:Display PDF(stored as a BLOB) as an image in MVC在 MVC 中将 PDF(存储为 BLOB)显示为图像
【发布时间】:2013-10-01 04:27:16
【问题描述】:

我必须在局部视图中显示 PDF(在 SQL Server 表中存储为 BLOB)。我对在表中存储为 BLOB 的“.jpeg”图像执行相同的操作。图像正在显示,但是,PDF 不是。我的控制器中有以下代码:

[Authorize]
public ActionResult Show3LeadImage(int id)
{
    Byte[] imageData = null;
    using (var scope = new PatientPersistenceScope())
    {
         searchRequest leadRequest = new searchRequest();
         leadRequest.CaseNumber = id;
         var mrx12LeadBitmap = _mrxSearchService.Get12Lead(leadRequest);
         imageData = mrx12LeadBitmap.Data12Leads[0].mrx3Lead;
         scope.Done();
    }
   return File(imageData,"image/png");//I have tried "FileContentResult,but it didnt work
 }

局部视图(.ascx)中的代码如下所示:

<object data='<%= Url.Action("Show3LeadImage", "CareRecord", new { id = Model.CareRecord.CaseNumber}) %>' type="application/pdf" style="width: 721px; height: 800px;" ></object>

我无权访问物理文件....BLOB 是我所拥有的。

甚至可以在部分视图中将 PDF 显示为图像吗?我遇到了很多文章,这些文章解释了如何在部分视图中使 PDF 可供下载。但我不希望我的文件可下载。这个功能是可以实现的还是我正在尝试做一些不可能的事情?

【问题讨论】:

  • 您可以通过将 pdf 放在磁盘上并将其路径保存在 sql 中来轻松实现它。我想,这会降低 SQL 读/写时间。

标签: asp.net-mvc pdf partial-views actionresult filecontentresult


【解决方案1】:

将 PDF 转换为图像并不像将其用作 PNG 那样简单。您需要使用 ImageMagick 或 ABCPdf 等库进行转换(示例:Convert PDF to image with high resolution

如果您想将 PDF 嵌入 HTML 中,有几种方法可以做到这一点,即Recommended way to embed PDF in HTML?

【讨论】:

    猜你喜欢
    • 2018-10-07
    • 2017-04-28
    • 1970-01-01
    • 2015-09-04
    • 2018-01-14
    • 2013-04-17
    • 2011-07-28
    • 2021-10-29
    相关资源
    最近更新 更多