簡體   English   中英

C# - NReco.PdfGenerator 非英文字符未呈現

[英]C# - NReco.PdfGenerator non english character not rendering

我正在使用 NReco.PdfGenerator 庫從 html 生成 pdf。 它適用於英語。 我還要求包括非英語語言(馬拉地語),在這種情況下,不能像預期的那樣工作。 渲染黑匣子。

這是我的操作方法:

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");

}

我也嘗試使用

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

但不工作。 還嘗試像這樣解碼為 un​​icode:

      byte[] utf8Bytes = Encoding.Default.GetBytes(htmlContent);

       byte[] utf16Bytes = Encoding.Convert(Encoding.UTF8, Encoding.Unicode, utf8Bytes);

htmlContent = Encoding.Unicode.GetString(utf16Bytes);

這對我也不起作用。 我的 html 包含像 विषय,मूल्यांकन प्रकार this 這樣的字符。 在我的 pdf 中,它顯示為

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>

任何幫助將不勝感激。

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

該命令對我有用。

我發布這個答案是因為萬一遇到同樣問題的人會得到幫助:

我通過使用NReco的 SelectPdf 找到了解決此問題的方法。

一些示例代碼:

public ActionResult ConverToPdf(string htmlContent)
        {
            try
            {

                // instantiate a html to 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 a new pdf document converting an 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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM