作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想使用 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();
实际 PDF 结果:
预期的 PDF 结果:
我该怎么做才能获得正确的结果?
最佳答案
当我使用阿拉伯字体时,我遇到了类似的对齐问题。阿拉伯语是一种 RTL 语言。您需要特定的 jar 以 RTL 语言生成 PDF。当前,当您尝试生成 PDF 时,模式是正常 LTR,因为您正在获取当前输出。
关于java - 使用 FlyingSaucer 将包含阿拉伯字符的 HTML 页面转换为 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26701878/
我在 mysql 数据库中有一个“价格”字段,其中包含以阿拉伯或波斯数字表示的产品价格。 数字示例:12345567890 //1234567890 我不知道如何格式化它以便以用户友好的方式格式化。我
由于单独使用 prawn gem 时阿拉伯字母显示为未知字符,因此我安装了 Arabic-Prawn gem 0.0.1 以阿拉伯语打印数据。我用下面的代码作为测试 Prawn::Document.g
我是一名优秀的程序员,十分优秀!