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

时间:2014-11-02 16:54:37

标签: java itext flying-saucer

我想使用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>
&#13;
&#13;
&#13;

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

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

是的,它与RTL有关但如果您没有选择与字体相关的话,那么您可以使用Arial字体,其中包含您需要的所有字符。  点击此链接 https://stackoverflow.com/a/47801584/3335776 看代码。

飞碟默认字体有些问题

you can find Complete article Here

相关问题