【问题标题】:Rotativa 1.6.4 / Wkhtmltopdf images not displaying (get blank image)Rotativa 1.6.4 / Wkhtmltopdf 图像不显示(获取空白图像)
【发布时间】:2015-11-18 04:27:27
【问题描述】:

我目前正在创建 MVC 5 Web 应用程序,以生成内部文档。

我在使用 Rotavia 创建 PDF 文件时遇到问题。当我创建文档时,得到一个黑色图像(看不到图像,看到空白边框)。

控制器:

     public ActionResult GeneratePDF(int id = 0)
        {


            var documentToGenerate = repository.getDocumentWithAttachment(id);


return new ViewAsPdf("MainTemplate/documentPDFView", documentToGenerate)
                {
                    FileName = (documentToGenerate.documentNumber + "_" + DateTime.Now.ToShortTimeString() + ".PDF"),
                    PageSize = Size.A4,
                    PageOrientation = Orientation.Landscape,
                    IsBackgroundDisabled = false,
                    IsGrayScale = false,
                    IsJavaScriptDisabled = true
                };

        }

查看部分:

// for test reason add two actions...
    <img src="@Url.Action("getFileAttachment", "Attachment", new { id = 18 })" alt="@file.value.name" style="height: 150px; width: 200px;">
    <img src="http://localhost:921/Document/Attachment/getFileAttachment/18" alt="@file.value.name" style="height: 150px; width: 200px;">

Attachment/getFileAttachment/18 响应 FileResult(测试 png 和 jpeg 文件,AllowAnonymous,工作正常...)

解决问题/问题的任何提示? :)

【问题讨论】:

  • 您是否尝试过使用 ActionAsPdf 而不是 ViewAsPdf?关于图片,您也可以在创建图片时尝试使用 Server.MapPath()。

标签: c# .net razor model-view-controller pdf-generation


【解决方案1】:

您应该使用例如&lt;img src="@Server.MapPath("relative_path_here")"&gt;,因为Rotativa 将图像、css 样式等作为本地资源。

也许你可以尝试使用:

<img src="@Server.MapPath(Url.Action("getFileAttachment", "Attachment", new { id = 18 }))">

【讨论】:

    猜你喜欢
    • 2012-12-19
    • 1970-01-01
    • 2021-06-28
    • 2014-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-12
    • 1970-01-01
    相关资源
    最近更新 更多