簡體   English   中英

NReco PDF在Azure上有黑色方塊

[英]NReco PDF has black squares on Azure

我使用NReco在Azure上生成PDF,它使用WkHtmlToPdf。 在我的本地服務器上,一切都很好。 但是在Azure上,它會渲染所有帶有黑色方塊的字體。

在此輸入圖像描述

我嘗試過在網上找到的所有東西。

這是我的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>

我也嘗試過使用Url.Content("~/Content/FreeSerif.ttf")

而我的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();

我的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>

每種解決方案都會產生黑色方塊 我在這里結束了我的智慧。 非常感謝您的幫助。

如果Azure意味着“Azure網站”,那么WkHtmlToPdf不支持它,這在NReco.PdfGenerator頁面上提到了FAQ部分。 在您的情況下,似乎PDF生成沒有錯誤,但出現黑色方塊,因為WkHtmlToPdf使用Windows GDI API,但在Azure WebSites中不起作用。

然而,PdfGenerator應該適用於Azure WebRole或Azure VM。 在這種情況下,Amazon EC2 T2微實例也是Azure WebSites的不錯選擇。

---更新---

目前,Azure應用程序(以前的網站)具有基於VM的訂閱(除“免費”和“共享”之外的所有計划),限制較少的托管環境允許wkhtmltopdf執行,並且在這種情況下可以使用NReco PdfGenerator包裝器。 請注意,仍然存在一些限制:例如,不呈現自定義字體(只能使用系統安裝的字體)。

我有一個類似的問題要解決這個問題,必須創建一個雲服務azure來生成pdf報告。 創建雲服務並正確生成pdf與我在案例中聲明的每個樣式我使用旋轉並正在努力完善留下一些鏈接,以便您可以看到如何創建雲服務天藍色的項目

雲服務示例

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM