使用ITextRenderer将html转换为PDF的阿拉伯语问题 [英] Arabic problems with converting html to PDF using ITextRenderer

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

问题描述

当我使用ITextRenderer将html转换为PDF时。这是我的代码

When I use ITextRenderer converting html to PDF.this is my code

ByteArrayOutputStream out = new ByteArrayOutputStream();

ITextRenderer renderer = new ITextRenderer();
String inputFile = "C://Users//Administrator//Desktop//aaa2.html";
String url = new File(inputFile).toURI().toURL().toString();
renderer.setDocument(url);
renderer.getSharedContext().setReplacedElementFactory(
        new B64ImgReplacedElementFactory());
    // 解决阿拉伯语问题
ITextFontResolver fontResolver = renderer.getFontResolver();
try {
    fontResolver.addFont("C://Users//Administrator//Desktop//arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
} catch (DocumentException e) {
    e.printStackTrace();
}

renderer.layout();
OutputStream outputStream = new FileOutputStream("C://Users//Administrator//Desktop//HTMLasPDF.pdf");
renderer.createPDF(outputStream, true);
/*PdfWriter writer = renderer.getWriter();

writer.open();
writer.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
OutputStream outputStream2 = new FileOutputStream(  "C://Users//Administrator//Desktop//HTMLasPDFcopy.txt");
renderer.createPDF(outputStream2);*/
renderer.finishPDF();
out.flush();
out.close();

实际PDF结果:

预期PDF结果:

如何制作阿拉伯语连字?

How to make arabic ligature?

推荐答案

我改变了使用wkhtmltopdf转换pdf的方式。

I change the way to convert pdf by using wkhtmltopdf.

这篇关于使用ITextRenderer将html转换为PDF的阿拉伯语问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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