简体   繁体   English

NReco PDF在Azure上有黑色方块

[英]NReco PDF has black squares on Azure

I am generating PDFs on Azure using NReco which uses WkHtmlToPdf. 我使用NReco在Azure上生成PDF,它使用WkHtmlToPdf。 On my local server everything generates just fine. 在我的本地服务器上,一切都很好。 On Azure however it renders all fonts with black squares. 但是在Azure上,它会渲染所有带有黑色方块的字体。

在此输入图像描述

I have tried everything I can find online. 我尝试过在网上找到的所有东西。

Here is my HTML: 这是我的HTML:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <style type="text/css">
        @@font-face {
            font-family: "FreeSerif";
            src: url(@(HttpContext.Current.Server.MapPath("~/Content/FreeSerif.ttf"))) format("truetype");
        }

        * {
            font-family:"FreeSerif", Helvetica, Arial, sans-serif;color:black;
        }
    </style>
</head>

I have also tried using Url.Content("~/Content/FreeSerif.ttf") 我也尝试过使用Url.Content("~/Content/FreeSerif.ttf")

And my C#: 而我的C#:

string htmlText = RenderPartialViewToString("~/Views/Templates/PDF/ListPDFView.cshtml", pdfList);

HtmlToPdfConverter nPdf = new HtmlToPdfConverter();
nPdf.Size = PageSize.Letter;
nPdf.Orientation = PageOrientation.Landscape;
nPdf.CustomWkHtmlArgs = "--encoding UTF-8";

pdfBuf = nPdf.GeneratePdf(htmlText);

Response.ContentType = "application/pdf";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Disposition", "Inline; filename=file.pdf");
Response.BinaryWrite(pdfBuf);
Response.Flush();
Response.End();

My web.config contains: 我的web.config包含:

<system.webServer>
    <staticContent>
        <remove fileExtension=".ttf" />
        <remove fileExtension=".svg" />
        <remove fileExtension=".eot" />
        <remove fileExtension=".woff" />
        <mimeMap fileExtension=".ttf" mimeType="font/truetype" />
        <mimeMap fileExtension=".svg" mimeType="image/svg+xml"  />
        <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
        <mimeMap fileExtension=".woff" mimeType="application/x-woff" />
    </staticContent>
</system.webServer>

Every solution results in black squares. 每种解决方案都会产生黑色方块 I am at my wits end here. 我在这里结束了我的智慧。 Your help is very appreciated. 非常感谢您的帮助。

If Azure means "Azure Websites" unfortunately it is not supported by WkHtmlToPdf and this is mentioned FAQ section on NReco.PdfGenerator page . 如果Azure意味着“Azure网站”,那么WkHtmlToPdf不支持它,这在NReco.PdfGenerator页面上提到了FAQ部分。 In your case it seems PDF is generated without errors but black squares appears because WkHtmlToPdf uses Windows GDI API which doesn't work at Azure WebSites. 在您的情况下,似乎PDF生成没有错误,但出现黑色方块,因为WkHtmlToPdf使用Windows GDI API,但在Azure WebSites中不起作用。

Nevertheless PdfGenerator should work fine for Azure WebRole or Azure VM. 然而,PdfGenerator应该适用于Azure WebRole或Azure VM。 Amazon EC2 T2 micro instance is also good alternative for Azure WebSites in this case. 在这种情况下,Amazon EC2 T2微实例也是Azure WebSites的不错选择。

--- UPDATE --- ---更新---

For now Azure Apps (former Websites) has VM-based subscriptions (all plans except "Free" and "Shared") with less restrictive hosting environment that allows wkhtmltopdf execution and NReco PdfGenerator wrapper can be used in this case. 目前,Azure应用程序(以前的网站)具有基于VM的订阅(除“免费”和“共享”之外的所有计划),限制较少的托管环境允许wkhtmltopdf执行,并且在这种情况下可以使用NReco PdfGenerator包装器。 Note that some limitations still exist: for example, custom fonts are not rendered (only system-installed fonts could be used). 请注意,仍然存在一些限制:例如,不呈现自定义字体(只能使用系统安装的字体)。

I had a similar problem to solve this had to create a cloud service azure to generate reports in pdf. 我有一个类似的问题要解决这个问题,必须创建一个云服务azure来生成pdf报告。 to create the cloud service and the pdf is generated correctly with every style declared in my case I use rotary and is working to perfection leave some links so you can see how to create a project for cloud services azure 创建云服务并正确生成pdf与我在案例中声明的每个样式我使用旋转并正在努力完善留下一些链接,以便您可以看到如何创建云服务天蓝色的项目

Cloud Services Example 云服务示例

https://www.visualstudio.com/en-us/docs/release/examples/azure/net-to-azure-cloud-services https://www.visualstudio.com/en-us/docs/release/examples/azure/net-to-azure-cloud-services

https://github.com/Microsoft/nodejstools/wiki/Azure-Cloud-Service-Projects https://github.com/Microsoft/nodejstools/wiki/Azure-Cloud-Service-Projects

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM