使用ITextRenderer在PDF文件中渲染Unicode(十六进制)字符

时间:2018-06-12 04:49:43

标签: spring-boot utf-8 thymeleaf

我正在使用Thymeleaf和Spring启动,我使用ITextRenderer从Thymeleaf模板生成PDF文件,我有一些Unicode(HEX)值来显示货币符号,但它不会呈现Unicode字符

我从此网址Currency Unicode reference

获取了货币符号Unicode

以下是我从Thymeleaf模板生成PDF的Java代码

String html = templateEngine.process("templates/Quote", context);
FileOutputStream os = null;
File parentDirectory=null;
try {
    OutputStream outputStream = new FileOutputStream(quoteNumber+".pdf");
    BufferedOutputStream bs= new BufferedOutputStream(outputStream);

    ITextRenderer renderer = new ITextRenderer();
    renderer.setDocumentFromString(html);
    renderer.layout();
    renderer.createPDF(bs,true);
    outputStream.close();
    Assert.notNull("greeting", "The templateName can not be null");
    final Context ctx = new Context();
    String processedHtml = templateEngine.process("greeting", ctx);
    String fileName = UUID.randomUUID().toString();             

} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    //e.printStackTrace();
    log.error("File not found >>> ",e);
} catch (IOException e) {
    // TODO Auto-generated catch block
    //e.printStackTrace();
    log.error("IO Exception >>> ",e);
}          
finally {
    if (os != null) {
        try {
            os.close();
        } catch (IOException e) { /*ignore*/ }
    }
} 

请帮我在生成的PDF中显示货币符号

0 个答案:

没有答案