gpt4 book ai didi

java - 使用 FlyingSaucer 将包含阿拉伯字符的 HTML 页面转换为 PDF

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:37:30 30 4
gpt4 key购买 nike

我想使用 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;">
&#x062C;&#x0645;&#x064A;&#x0639; &#x0627;&#x0644;&#x062D;&#x0642;&#x0648;&#x0642;<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();

实际 PDF 结果: actual result

预期的 PDF 结果: expected result

我该怎么做才能获得正确的结果?

最佳答案

当我使用阿拉伯字体时,我遇到了类似的对齐问题。阿拉伯语是一种 RTL 语言。您需要特定的 jar 以 RTL 语言生成 PDF。当前,当您尝试生成 PDF 时,模式是正常 LTR,因为您正在获取当前输出。

关于java - 使用 FlyingSaucer 将包含阿拉伯字符的 HTML 页面转换为 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26701878/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com