Вопросительный знак с кириллицей и iTextSharp c # - PullRequest
0 голосов
/ 16 января 2019

Я создаю PDF с помощью iTextSharp (c #). Я использую HTML-код и CSS-файл для форматирования PDF. Я не могу решить проблему с кириллицей. Вот мой код:

MemoryStream ms = new MemoryStream();

PdfStamper stamper = new PdfStamper(reader, ms);

FontFactory.Register(HttpContext.Current.Server.MapPath("~/PdfGenerator/fonts/YanoneKaffeesatz-Regular.ttf"), "Yanone Kaffeesatz");

string StyleFront = File.ReadAllText(HttpContext.Current.Server.MapPath("~/PdfGenerator/css/styleFront.css"));

PdfContentByte cb = stamper.GetOverContent(1);

Paragraph Paragrafo = new Paragraph();

Paragrafo.SetLeading(0, 1.0f);

Paragrafo.Alignment = Element.ALIGN_RIGHT;

string Titolo = HttpUtility.HtmlDecode("О КОМПАНИИ");

foreach (var element in HTMLParser(Titolo, StyleFront)) { Paragrafo.Add(element); }

ColumnText CtTitolo = new ColumnText(cb);

CtTitolo.SetLeading(0, 1f);

CtTitolo.SetSimpleColumn(28.35f, 686f, 283.46f, 722.83f, 0, Element.ALIGN_RIGHT);

CtTitolo.AddElement(Paragrafo);

CtTitolo.Go();

stamper.FormFlattening = true;

stamper.Close();

context.Response.ContentType = "application/pdf";

context.Response.AddHeader("Content-Type", "application/pdf; charset=UTF8");

context.Response.AddHeader("Cache-Control", "no-cache");

context.Response.AddHeader("Content-Disposition", 

string.Format("inline;filename={0}{1}.pdf", "Documnent_", article.Title));

context.Response.BinaryWrite(ms.ToArray());

context.Response.End();


private ElementList HTMLParser(string HTML, string CSS)
{

   try
   {
       return XMLWorkerHelper.ParseToElementList(HTML, CSS);
   }
   catch
   {
       ElementList error = new ElementList();             
    }
}

Шрифт "Yanone Kaffeesatz" должен быть совместим с русскими символами. Я думаю, что проблема в HTMLParser (Titolo, StyleFront), но я не знаю, как решить. Кто-нибудь может мне помочь? Спасибо

...