我试图通过使用iText html2pdf将HTML页面转换为PDF文件,但我发现阿拉伯语文本在转换后被逆转。在HTML页面上,文本以"#"开头,但在PDF中,文本以"#"结尾,字符完全错误。查看以下图片了解更多细节:HTML页面PDF页
有谁知道如何解决这个问题吗?
test.html
<!DOCTYPE html>
<html>
<head>
<meta content="text/html" charset="utf-8">
<title>Arabic testing</title>
<style type="text/css">
body {
direction: rtl;
}
</style>
</head>
<body>
<div>حاوية #</div>
</body>
</html>
@Test
public void convert() {
File htmlFile = new File("/Users/scott/Downloads/pdf/test.html");
File pdfFile = new File("/Users/scott/Downloads/pdf/test.pdf");
try {
PdfWriter writer = new PdfWriter(pdfFile.getPath());
PdfDocument pdfDoc = new PdfDocument(writer);
pdfDoc.setTagged();
pdfDoc.setDefaultPageSize(PageSize.A4.rotate());
ConverterProperties converterProperties = new ConverterProperties();
converterProperties.setCharset(StandardCharsets.UTF_8.name());
FontProvider fontProvider = new DefaultFontProvider(false, false, false);
fontProvider.addFont("/Users/scott/Downloads/pdf/Amiri-Regular.ttf");
converterProperties.setFontProvider(fontProvider);
HtmlConverter.convertToPdf(new FileInputStream(htmlFile), pdfDoc, converterProperties);
} catch (IOException e) {
log.error("Render PDF failed, ", e);
}
}
根据@ andr