Winnovative Html to PDF converter not rendering font-face fonts

2.1k views Asked by At

I'm using Winnovative's Html to PDF converter to print my page to PDF.

// Get a PDF of the URL.
Document document = new Document();
//document.LicenseKey = PDFUtility.LicenseKey;

PdfPage page = document.Pages.AddNewPage(PdfPageSize.A4, new Margins(10, 10, 0, 0), PdfPageOrientation.Portrait);

HtmlToPdfElement pageToPrint = new HtmlToPdfElement(sURL);
page.AddElement(pageToPrint);

// Setup response
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename ={0}", sPage + ".pdf"));

document.Save(context.Response.OutputStream);

My header tags have a font face on them. This works fine locally and renders with the custom font. However on my dev and test servers it does not render the header tags at all. It does leave space where the header tags should be.

When we changed our headers to Arial the PDF renders with the headers in all environments.

We've checked permission on the font files (set permissions to full control for everyone). That didn't change anything.

Something to do with the font face is not working on our server and we can't figure out what.

3

There are 3 answers

0
user2780703 On

You have to check if your font files are accessible in a browser from the server itself. Put your HTML code in a HTML file and open that file from the test server in a browser. If the HTML file is displayed well in browser it should be rendered well in PDF too.

You should also make sure that the IIS from the server has the ttf or woff (not sure what exactly you reference in @font-face) set in accepted MIME types, otherwise these files will not be served by web server.

0
Winnovative On

Yes, you have to make sure the font files are enabled in your web server MIME types. Winnovative HTML to PDF converter works well with all types of we fonts. There is a complete example with C# and HTML code using @ont-face rules in Convert HTML with Web Fonts to PDF demo .

0
user2173353 On

I had a similar problem showing web fonts in my solution as well.

It turns out that woff2 fonts did not get rendered at all.

Once I switched to the woff file format, everything worked as expected.

From what I saw, there is no setting that I haven't enabled in the converter, so I guess woff2 is not supported.