【发布时间】: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