0

有如下代码:

    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 中加入一些波兰语字母(如“ą”、“ę” 等)怎么做?

4

1 回答 1

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);
于 2012-04-14T04:06:40.187 回答