I am using NReco.PdfGenerator library to generate pdf from html. It is working fine for english language. I also required to include non-english language(marathi) , in that case not working like as expected. rendering black boxes.
This is my action method:
public ActionResult Assesment_DownloadResultSummaryData(string htmlContent){
var htmlToPdf = new HtmlToPdfConverter();
var margins = new PageMargins();
margins.Bottom = 10; // margins.Left = 5;margins.Right = 5;
margins.Top = 10;
htmlToPdf.Margins = margins;
htmlToPdf.CustomWkHtmlPageArgs = "--enable-smart-shrinking --encoding <encoding>";
htmlToPdf.PageFooterHtml = $@"page <span class=""page""></span> of <span class=""topage""></span><br />";
//htmlToPdf.Orientation = NReco.PdfGenerator.PageOrientation.Portrait;
htmlToPdf.Zoom = 1.0f;
return File(htmlToPdf.GeneratePdf(htmlContent, null), "application/pdf","myFile.pdf");
}
I am also tried using
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
but not working. also put a try on decoding to unicode like this :
byte[] utf8Bytes = Encoding.Default.GetBytes(htmlContent);
byte[] utf16Bytes = Encoding.Convert(Encoding.UTF8, Encoding.Unicode, utf8Bytes);
htmlContent = Encoding.Unicode.GetString(utf16Bytes);
this also not worked for me. My html contains characters like विषय,मूल्यांकन प्रकार this . in my pdf its showing as मà¥à¤²à¥à¤¯à¤¾à¤‚कन निकाल</p>
Some part of htmlContent:
<tbody><tr>
<td colspan="6"><p><b>मुल्यांकन निकाल</b></p></td>
</tr>
<tr>
<td style="width:5%"><h4><b>वर्ग :</b></h4></td>
<td style="width:10%;text-align:left;"><h4><b>Class 1-A</b></h4></td>
<td style="width:10%"><h4><b>बॅच :</b></h4></td>
<td style="width:40%;text-align:left;"><h4><b> 25-07-2017-Class 1-A-General Knowledge-English-1</b></h4></td>
<td style="width:20%"><h4><b>विद्यार्थ्यांची एकूण संख्या :</b></h4></td>
<td style="width:10%"><h4><b>18</b></h4></td>
</tr>
<tr >
<td style="width:20%"><h4><b>विषय :</b></h4></td>
<td style="width:10%;text-align:left;"><h4><b>English</b></h4></td>
<td style="width:10%"><h4><b>विषय :</b></h4></td>
<td style="width:30%;text-align:left;"><h4><b>General Knowledge</b></h4></td>
<td style="width:20%"><h4><b>उपस्थित विद्यार्थी संख्या :</b></h4></td>
<td style="width:10%"><h4><b>17</b></h4></td>
</tr>
</tbody>
Any help will be appreciated.