Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc HTML到PDF itextSharp-处理多种字体和unicode_Asp.net Mvc_Fonts_Itext_Html To Pdf - Fatal编程技术网

Asp.net mvc HTML到PDF itextSharp-处理多种字体和unicode

Asp.net mvc HTML到PDF itextSharp-处理多种字体和unicode,asp.net-mvc,fonts,itext,html-to-pdf,Asp.net Mvc,Fonts,Itext,Html To Pdf,各位,我们正在尝试在ASP.NETMVC5项目中通过itextSharp(v5.x)将HTML转换为PDF。请注意,html包含中文和英文字符(作为示例),并根据文化设置了数字格式 虽然我们确实注册了以下字体:Arial、Microsoft Yahei和Yu Gothic(浏览器基本上使用这些字体来显示我们的内容),但PDF不知何故只使用Yahei,因此很少有字符被吞没 我们已经确保html包含上述三种字体的字体系列,我们还将这些字体作为字体系列加载tagstyle,编码设置为Identity-

各位,我们正在尝试在ASP.NETMVC5项目中通过itextSharp(v5.x)将HTML转换为PDF。请注意,html包含中文和英文字符(作为示例),并根据文化设置了数字格式

虽然我们确实注册了以下字体:Arial、Microsoft Yahei和Yu Gothic(浏览器基本上使用这些字体来显示我们的内容),但PDF不知何故只使用Yahei,因此很少有字符被吞没

我们已经确保html包含上述三种字体的字体系列,我们还将这些字体作为字体系列加载tagstyle,编码设置为Identity-H

发生这种情况是因为itext不允许在html中使用多种字体进行渲染吗?(HTML是从通过后端代码填充数据的模板中提取的

编辑: 下面是我们需要帮助的代码片段部分: (我们需要在html使用时注册多个字体。但是只应用上次注册的字体)


Rotativa在这方面做得很好。请发布代码的关键部分,因为您的问题现在还不清楚。@Steve,我检查过了。看起来不错。但是iText5嵌入到我们的许多应用程序中。因此替换它有点困难:(@AmedeeVanGasse,我已经发布了代码片段。我们需要帮助注册多种字体(我们已经在html中提到过)。
StringReader sr = new StringReader(html);
Document pdfDoc = new Document(iTextSharp.text.PageSize.A4, 0f, 0f, 0f, 0f);  
//Register a single font 
//FontFactory.Register(Path.Combine(System.Environment.GetEnvironmentVariable("windir"), "Fonts") + "\\arial-unicode-ms.ttf", "Arial Unicode MS");
// create a style sheet and set the encoding to Identity-H        
StyleSheet style = new StyleSheet();               
//Set the default body font to our registered font's internal name                
style.LoadTagStyle(HtmlTags.BODY, HtmlTags.FACE, "Arial Unicode MS");           
//Set the default encoding to support Unicode characters               
style.LoadTagStyle(HtmlTags.BODY, HtmlTags.ENCODING, BaseFont.IDENTITY_H);     
HTMLWorker htmlparser = new HTMLWorker(pdfDoc, null, style);