【问题标题】:itext7.pdfHTML library how to fix it to support multiple languagesitext7.pdfHTML 库如何修复它以支持多种语言
【发布时间】:2021-08-29 16:01:46
【问题描述】:

我创建了一个示例项目,用于尝试测试 itext7.pdfHTML 库。我认为这个库只支持英语,但我认为不可能只记住一种语言支持。请帮我修复它以支持多种语言。 我只会将 html 转换为 pdf 并且 我使用 itext7.pdfhtml 3.0.4

控制器

public IActionResult TestPDFHtml()
        {
            string html = @"<html><head><meta http-equiv=""content-type"" content=""text/html""; charset=""UTF-8""></head><body>สวัสดี</body>";
            TestPDF test = new TestPDF();
            byte[] vs = test.creatPDFByte(html);
            return File(vs, "application/pdf");
        }

代码方法 creatPDFByte

public byte[] creatPDFByte(string pdfHTML)
        {
            byte[] buffer;
            try
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    using (PdfWriter pw = new PdfWriter(ms))
                    {
                        pw.SetCloseStream(true);
                        using (PdfDocument pdfDoc = new PdfDocument(pw))
                        {
                            ConverterProperties cProps = new ConverterProperties();
                            cProps.SetCharset("UTF-8");
                            pdfDoc.SetDefaultPageSize(PageSize.A4);
                            pdfDoc.SetCloseWriter(true);
                            pdfDoc.SetCloseReader(true);
                            pdfDoc.SetFlushUnusedObjects(true);
                            HtmlConverter.ConvertToPdf(pdfHTML, pdfDoc, cProps);
                        }
                    }
                    
                    buffer = ms.ToArray();
                }
            }
            catch ...

【问题讨论】:

  • “我认为这个库只支持英语” - 你为什么这么认为?
  • 我投票结束这个问题,因为这是一个 X-Y 问题。

标签: c# .net pdf itext


【解决方案1】:

你为什么这么认为?您是否尝试过在 css 中添加字体,因为默认字体可能不支持您的语言。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 2015-05-16
    • 1970-01-01
    相关资源
    最近更新 更多