加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-15 00:34:02 所属栏目:Java 来源:网络整理
导读:我想使用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/xhtml
我想使用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结果:

预期PDF结果:

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

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读