我正在使用 openhtmltopdf 库将 html 转换为 pdf,但转换后的 pdf 添加了“#”,而不是“ı”、“ş”、“Ş”、“ç”、“Ç”、“Ö”等字符。我该如何解决?
Java代码:
ByteArrayOutputStream renderedPdfBytes = new ByteArrayOutputStream();
PdfRendererBuilder builder = new PdfRendererBuilder();
builder.withHtmlContent(htmlContent, "/");
builder.toStream(renderedPdfBytes);
builder.run();
renderedPdfBytes.close();
byte[] renderedPdf = renderedPdfBytes.toByteArray();
try (FileOutputStream fos = new FileOutputStream(pdfFile)) {
fos.write(renderedPdf);
}
HTML内容:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<body>
<span class="close-icon close"></span>
<div class="modal-content">
<div class="modal-header"><h2>İade Prosedürü 27.09.2023</h2></div>
<div class="modal-body" style="margin-bottom: 50px;"><p>İade edilmek istenen.</p></div>
</div>
</body>
</html>
如果您在使用 openhtmltopdf 库生成的 PDF 中遇到字符无法正确显示的问题,则可能与字体嵌入或字体支持有关。 您可以修改代码以包含具有适当字符支持的自定义字体。