我想使用 FlyingSaucer 将包含阿拉伯字符的 HTML 页面转换为 PDF 文件,但生成的 PDF 不包含组合字符并向后打印输出。
HTML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body style="font-size:15px;font-family: Arial Unicode MS;">
<center style="font-size: 18px; font-family: Arial Unicode MS;">
<b>
<i style="font-family: Arial Unicode MS;">
جميع الحقوق<br />
</i>
</b>
</center>
</body>
</html>
Java 摘录:
String inputFile = "c:\\html.html";
String url = new File(inputFile).toURI().toURL().toString();
String outputFile = "c:\\html.pdf";
OutputStream os = new FileOutputStream(outputFile);
ITextRenderer renderer = new ITextRenderer();
renderer.getFontResolver().addFont("c://ARIALUNI.TTF", BaseFont.IDENTITY_H,BaseFont.EMBEDDED);
renderer.setDocument(url);
renderer.layout();
renderer.createPDF(os);
os.close();
Actual PDF Result: ![actual result](https://i.stack.imgur.com/jBe1p.png)
Expected PDF Result: ![expected result](https://i.stack.imgur.com/d9wXr.png)
我该怎么做才能获得正确的结果?
当我使用阿拉伯字体时,我遇到了类似的对齐问题。阿拉伯语是一种 RTL 语言。您需要特定的 jar 来生成 RTL 语言的 PDF。目前,当您尝试生成 PDF 时,模式为正常 LTR,因此您将获得当前输出。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)