Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.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
C# 它是锋利的西里尔字母_C#_Itextsharp - Fatal编程技术网

C# 它是锋利的西里尔字母

C# 它是锋利的西里尔字母,c#,itextsharp,C#,Itextsharp,我过去常常从我的razor视图生成pdf文件,效果很好,但我不能显示像č,ć这样的西里尔字母。我什么都试过了,但都没用 我必须告诉HtmlWorker使用不同的字体: using (var htmlViewReader = new StringReader(htmlText)) { using (var htmlWorker = new HTMLWorker(p

我过去常常从我的razor视图生成pdf文件,效果很好,但我不能显示像č,ć这样的西里尔字母。我什么都试过了,但都没用

我必须告诉HtmlWorker使用不同的字体:

 using (var htmlViewReader = new StringReader(htmlText))
                    {                       
                        using (var htmlWorker = new HTMLWorker(pdfDocument))
                        {                            

                            htmlWorker.Parse(htmlViewReader);
                        }
                    }
你能帮忙吗

编辑:

我漏了一行

styleSheet.LoadTagStyle(HtmlTags.BODY, HtmlTags.ENCODING, BaseFont.IDENTITY_H);
其余部分与答案相同。

如果您将StandardPdfRenderer的呈现方法更改为以下代码段,它应该可以工作:

public byte[] Render(string htmlText, string pageTitle)
{
    byte[] renderedBuffer;

    using (var outputMemoryStream = new MemoryStream())
    {
        using (var pdfDocument = new Document(PageSize.A4, HorizontalMargin, HorizontalMargin, VerticalMargin, VerticalMargin))
        {
            string arialuniTff = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");
            iTextSharp.text.FontFactory.Register(arialuniTff);

            PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDocument, outputMemoryStream);

            pdfWriter.CloseStream = false;
            pdfWriter.PageEvent = new PrintHeaderFooter { Title = pageTitle };
            pdfDocument.Open();

            using (var htmlViewReader = new StringReader(htmlText))
            {
                using (var htmlWorker = new HTMLWorker(pdfDocument))
                {
                    var styleSheet = new iTextSharp.text.html.simpleparser.StyleSheet();
                    styleSheet.LoadTagStyle(HtmlTags.BODY, HtmlTags.FACE, "Arial Unicode MS");
                    styleSheet.LoadTagStyle(HtmlTags.BODY, HtmlTags.ENCODING, BaseFont.IDENTITY_H);
                    htmlWorker.SetStyleSheet(styleSheet);

                    htmlWorker.Parse(htmlViewReader);
                }
            }
        }

        renderedBuffer = new byte[outputMemoryStream.Position];
        outputMemoryStream.Position = 0;
        outputMemoryStream.Read(renderedBuffer, 0, renderedBuffer.Length);
    }

    return renderedBuffer;
}

可能是重复的我尝试了这个,但它不起作用谢谢,我将代码与我的代码进行了比较,我缺少一行样式表。LoadTagStyle(HtmlTags.BODY,HtmlTags.ENCODING,BaseFont.IDENTITY_H);其余的和我的一样。当做