有一段代码如下:
var workStream = new MemoryStream();
var doc = new Document(PageSize.LETTER, 10, 10, 42, 35);
PdfWriter.GetInstance(doc, workStream).CloseStream = false;
doc.Open();
var builder = new StringBuilder();
builder.Append("MY LONG HTML TEXT");
var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(builder.ToString()), null);
foreach (var htmlElement in parsedHtmlElements)
doc.Add(htmlElement);
doc.Close();
byte[] byteInfo = workStream.ToArray();
workStream.Write(byteInfo, 0, byteInfo.Length);
workStream.Position = 0;
return new FileStreamResult(workStream, "application/pdf")
问题 - 我希望在我的pdf中有一些波兰语字母(如“ą”,“ę”等) 怎么做?
答案 0 :(得分:1)
您需要注册字体,然后使用样式表指定编码:
FontFactory.Register("c:\\windows\\fonts\\tahoma.ttf");
StyleSheet styles = new StyleSheet();
styles.LoadTagStyle(HtmlTags.BODY, HtmlTags.FONTFAMILY, "tahoma");
styles.LoadTagStyle(HtmlTags.BODY, HtmlTags.ENCODING, "Identity-H");
var html = @"data";
var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(html), styles);