使用FlyingSaucer将包含阿拉伯字符的HTML页面转换为PDF [英] Convert HTML page containing Arabic characters to PDF using FlyingSaucer

查看:139
本文介绍了使用FlyingSaucer将包含阿拉伯字符的HTML页面转换为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用FlyingSaucer将包含阿拉伯字符的HTML页面转换为PDF文件,但生成的PDF不包含组合字符并向后打印输出。

I want to convert an HTML page that contains Arabic characters to a PDF file using FlyingSaucer, but the generated PDF does not contain combined characters and prints the output backwards.

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结果:

我可以做些什么来获得正确的结果?

What can I do to obtain the right result?

推荐答案

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

Yes it related to RTL but if you have no choice related to fonts then you can use Arial fonts which has all characters required by you. follow this link https://stackoverflow.com/a/47801584/3335776 to see code.

飞碟默认字体有些问题

你可以在这里找到完整的文章

这篇关于使用FlyingSaucer将包含阿拉伯字符的HTML页面转换为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆