asp.net - C# - NReco.PdfGenerator non english character not rendering -
i using nreco.pdfgenerator library generate pdf html. working fine english language. required include non-english language(marathi) , in case not working expected. rendering black boxes.
this 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 tried using
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
but not working. put try on decoding unicode :
byte[] utf8bytes = encoding.default.getbytes(htmlcontent); byte[] utf16bytes = encoding.convert(encoding.utf8, encoding.unicode, utf8bytes); htmlcontent = encoding.unicode.getstring(utf16bytes);
this not worked me. html contains characters विषय,मूल्यांकन प्रकार . in pdf showing मà¥à¤²à¥à¤¯à¤¾à¤‚कन निकाल
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 appreciated.
i posting answer because in case 1 facing same problem helped:
i found solution problem using selectpdf insted of nreco .
some sample code:
public actionresult convertopdf(string htmlcontent) { try { // instantiate html pdf converter object htmltopdf converter = new htmltopdf(); pdfpagesize pagesize = pdfpagesize.a4; pdfpageorientation pdforientation = pdfpageorientation.portrait; int webpagewidth = 1024; // set converter options converter.options.pdfpagesize = pagesize; converter.options.pdfpageorientation = pdforientation; converter.options.webpagewidth = webpagewidth; converter.options.marginleft = 10; converter.options.marginright = 10; converter.options.margintop = 5; converter.options.marginbottom = 5; //converter.options.webpageheight = webpageheight; // create new pdf document converting url pdfdocument doc = converter.converthtmlstring(htmlcontent); // save pdf document byte[] pdf = doc.save(); // close pdf document doc.close(); // return resulted pdf document fileresult fileresult = new filecontentresult(pdf, "application/pdf"); fileresult.filedownloadname = "document.pdf"; return fileresult; }
Comments
Post a Comment