【问题标题】:Missing image from Rotativa PDF fileRotativa PDF 文件中缺少图像
【发布时间】:2014-09-27 01:14:33
【问题描述】:

我们正在使用Rotativa 在网络服务器上保存该页面的永久 PDF 副本。这是构建和保存它的 ASP.NET MVC 4 代码:

 var pdfResult = new ActionAsPdf("Index", new { orderId = orderValidated.orderID }) { FileName = filePath };

 var binary = pdfResult.BuildPdf(ControllerContext);

 // writes only if the file does not exist, we need to keep first authentic print of it.
 if (System.IO.File.Exists(filePath) == false)
 {
    System.IO.File.WriteAllBytes(filePath, binary);
 }

我们使用特定的“css”文件在页面<head> 部分进行打印:

<head>
  <link media=all href="/Content/invoice.css" type=text/css rel=stylesheet>
  <link media=print href="/Content/printInv.css" type=text/css rel=stylesheet>      
</head>

“css”打印版本包含:

#logo {background: url(/assets/images/logo-plain.gif) no-repeat; height: 56px}

并且 PDF 文档中缺少 *.gif 图像(屏幕上存在)。

知道它丢失的原因吗?

谢谢。

【问题讨论】:

    标签: css asp.net asp.net-mvc pdf pdf-generation


    【解决方案1】:

    我认为这是 Rotativa 的问题。

    我解决的方法是使用图像标签内联插入背景图像,然后使用 css 定位它:

       #bg {
            position: absolute;
            top: 8px;
            left: 0px;
            z-index: 0;
        }
    
    <img src="@Url.Content("~/content/background-image.jpg")" id="bg" />
    

    【讨论】:

      【解决方案2】:

      据我所知,Rotativa 在 gif 图像方面存在问题。尝试使用 jpg 或 png。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-20
        • 2013-07-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-29
        相关资源
        最近更新 更多