NReco PDF has black squares on Azure

I am creating PDF files on Azure using NReco, which uses WkHtmlToPdf. On my local server, everything works out just fine. However, on Azure, it displays all fonts with black squares.

enter image description here

I have tried everything that I can find on the Internet.

Here is my 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 also tried using Url.Content("~/Content/FreeSerif.ttf")

And my 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 file contains:

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

Each decision leads to the appearance of black squares. I am here on my way. Your help is greatly appreciated.

+7
c # pdf wkhtmltopdf azure
source share
2 answers

If Azure means "Azure Websites", unfortunately it is not supported by WkHtmlToPdf, and this is mentioned in the FAQ section of the NReco.PdfGenerator page . In your case, it seems that the PDF is created without errors, but black squares appear because WkHtmlToPdf uses the Windows GDI API, which does not work on Azure WebSites.

However, PdfGenerator should work just fine for Azure WebRole or Azure VM. The Amazon EC2 T2 micro instance is also a good alternative for Azure WebSites in this case.

--- UPDATE ---

Currently, Azure Apps (former sites) has VM-based subscriptions (all plans except for "Free" and "Shared"), with a less restrictive hosting environment that allows you to use wkhtmltopdf and the NReco PdfGenerator shell in this case. Please note that some restrictions still exist: for example, custom fonts are not displayed (only fonts installed by the system can be used).

+3
source share

I had a similar problem to solve this problem in order to create an azure cloud service for creating pdf reports. to create a cloud service, and pdf is created correctly with each declared style in my case, I use rotational and works to perfection, leave some links so you can see how to create a project for azure cloud services

Cloud Services Example

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

0
source share

All Articles