Rotativa 1.6.4 / Wkhtmltopdf 图像不显示(得到空白图像)

Rotativa 1.6.4 / Wkhtmltopdf images not displaying (get blank image)

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

我在使用 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,工作正常...)

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

例如,您应该使用 <img src="@Server.MapPath("relative_path_here")">,因为 Rotativa 获取图像、css 样式等作为本地资源。

也许你可以尝试使用:

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