【发布时间】: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 问题。