我使用iTextSharp(c#)创建PDF。我使用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)上,但我不知道如何解决。 有人能帮我吗? 谢谢