C#-NReco.PdfGenerator非英语字符未呈现
我正在使用NReco.PdfGenerator库从html生成pdf。对于英语来说,这很好。我还要求包括非英语语言(马拉地语),在这种情况下不能像预期的那样工作。渲染黑盒 这是我的行动方法:C#-NReco.PdfGenerator非英语字符未呈现,c#,asp.net,asp.net-mvc,nreco,C#,Asp.net,Asp.net Mvc,Nreco,我正在使用NReco.PdfGenerator库从html生成pdf。对于英语来说,这很好。我还要求包括非英语语言(马拉地语),在这种情况下不能像预期的那样工作。渲染黑盒 这是我的行动方法: public ActionResult Assesment_DownloadResultSummaryData(string htmlContent){ var htmlToPdf = new HtmlToPdfConverter(); var margins =
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");
}
这对我也不起作用。
我的html包含如下字符विषय,मूल्यांकन प्रकार 这在我的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>
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;
}
मुल्यांकन निकाल
वर्ग :
1-A类
बॅच :
25-07-2017-Class 1-A-General Knowledge-English-1
विद्यार्थ्यांची एकूण संख्या :
18
विषय :
英语
विषय :
常识
उपस्थित विद्यार्थी संख्या :
17
任何帮助都将不胜感激。我将发布此答案,因为万一有人遇到同样的问题,我将 获得帮助:
<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>
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;
}
我找到了一个解决这个问题的办法,用NReco代替
一些示例代码:
<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>
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;
}
该命令对我有效。您在pdf中使用的字体是否确实包含您试图放入pdf中的tekst的字形?视图中的显示正确。如果没有“htmlContent”变量的值,很难说出具体的内容。wkhtmltopdf可能会回退到不包含马拉地字符的字体。是否有任何方法包含这些字符。