HiqPdf - Everything works in my local with HiqPDF with 'Evaluation watermark', but when it is deployed in server(Azure), it throws error:
Error: Cannot convert to PDF. Could not add demo watermark. Invalid font.
I am sending html to convert to pdf.
Any help?
HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
htmlToPdfConverter.Document.PageSize = PdfPageSize.A4;
switch (htmlModel.PageOrientation)
{
case Constants.PAGE_ORIENTATION_PORTRAIT:
htmlToPdfConverter.Document.PageOrientation = PdfPageOrientation.Portrait;
break;
default:
htmlToPdfConverter.Document.PageOrientation = PdfPageOrientation.Landscape;
break;
}
htmlToPdfConverter.Document.Margins = new PdfMargins(10, 10, 10, 10);
htmlToPdfConverter.SerialNumber = "";
if (!string.IsNullOrEmpty(htmlModel.ElementSelector))
{
htmlToPdfConverter.ConvertedHtmlElementSelector = htmlModel.ElementSelector;
}
string decodedHtml = htmlModel.HtmlString.Replace("$ReplaceSign1$", "<").Replace("$ReplaceSign2$", ">");
htmlBytes = htmlToPdfConverter.ConvertHtmlToMemory(decodedHtml, HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority);
TL;DR:
Use
Add-Font.ps1from here: https://github.com/wormeyman/FindFonts to install the Microsoft Sans Serif font inC:\Windows\Fonts\micross.ttfinto your Docker container or Windows Server.If it doesn't work, HiqPdf may need a different font. Use Process Monitor from SysInternals to find out which one is needed.
Explanation
I got the same error when I tried to use Winnovative HTML-to-PDF in a Windows Server 2019 Docker container. The reason is that the docker base image for Windows Server doesn't contain the fonts Windows 10 contains and a specific font is needed for the conversion. In my case it was Microsoft Sans Serif. I used Process Monitor to find out which font(s) are needed.
Finding out needed font with Process Monitor
First use the "Filter" button to add a filter for "Process Name is fontdrvhost.exe":
Then capture the activity during PDF conversion. You'll see which fonts are accessed in the Path column:
Now we know which font we need.
Installing the font
Download
Add-Font.ps1from here: https://github.com/wormeyman/FindFonts and copy it to your server/container. I created aC:\fontsfolder and copied the script into it for convenience.Then copy the needed font into the same folder. In my case it was
C:\Windows\Fonts\micross.ttf.Run the script to install the font:
Now Html-PDF conversion should work properly.