0

I am converting an HTML text string to pdf with the C#.net wrapper "NReco.PdfGenerator" for wkhtmltopdf on Windows Application. When I am converting html text which have Custom/Non-Unicode Fonts like "Kurti Dev 010" then wkhtmltipdf not generating same fonts pdf file. So PDF text can't be readable.

string dataText = "HTML TEXT DATA"; 
var margins = new PageMargins(); 
var htmlToPdf = new HtmlToPdfConverter(); 
margins.Top = 5; 
htmlToPdf.Zoom = 1f; 
margins.Bottom = 15; 
margins.Left = 10; 
margins.Right = 5; 
htmlToPdf.Margins = margins; 
htmlToPdf.Size = NReco.PdfGenerator.PageSize.A4; 
htmlToPdf.Orientation = PageOrientation.Portrait; 
htmlToPdf.GeneratePdf(dataText, null, FILEPATH);

What is the solution for it to generate PDF with same custom/Non-unicode fonts.

xyz
  • 1
  • 1

1 Answers1

0

First of all, please ensure that you have this meta tag in your HTML <head> section:

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

Another reason can be: to use your font wkhtmltopdf needs to download it, and it might be possible that it cannot do that for some reason (for instance, a relative URL or path is specified in HTML for "GeneratePdf" method, or URL is not accessible for some reason from the hosting environment where .NET app is running). If you reference font file as a local file it makes sense to ensure that

  1. wkhtmltopdf can use it - try to run wkhtmltopdf.exe for your HTML in the command line to ensure that it produces correct PDF output
  2. local files access is enabled ("--enable-local-file-access" option), see https://wkhtmltopdf.org/usage/wkhtmltopdf.txt

You code snippet doesn't include any HTML , so it is not possible to determine exact reason of the issue.

Vitaliy Fedorchenko
  • 8,447
  • 3
  • 37
  • 34