码迷,mamicode.com
首页 > Web开发 > 详细

xhtmlrenderer把html转换成pdf打印问题

时间:2016-05-11 12:53:19      阅读:387      评论:0      收藏:0      [点我收藏+]

标签:

1、解决中文显示:

加上中文字体:

private static final String WIN_FONT_SUN = "C:/Windows/Fonts/simsun.ttc";
    private static final String WIN_FONT_HEI = "C:/Windows/Fonts/simhei.ttf";
    private static final String LINUX_FONT_SUN = "/usr/share/fonts/my_fonts/simsun.ttc";
    private static final String LINUX_FONT_HEI = "/usr/share/fonts/my_fonts/STZHONGS.TTF";


if (isWindows())
{
addFont(fontResolver, WIN_FONT_SUN);
addFont(fontResolver, WIN_FONT_HEI);
}
else
{

addFont(fontResolver, LINUX_FONT_SUN);
addFont(fontResolver, LINUX_FONT_HEI);
}

private static void addFont(ITextFontResolver fontResolver, String font) throws DocumentException, IOException
{
if (new File(font).exists())
{
fontResolver.addFont(font, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
}
else
{
log.info(font + "===================================不存在");
}
}

 

2、解决,renderer.setDocument(url)

解决无法跳转导致的,无法加载xml,并且html文件中没有错误,每个标签都正常关闭,对齐。则很可能就是url,被拦截了。

一般是要放到白名单中,或者filter的白名单中

 

private static final String WIN_FONT_SUN = "C:/Windows/Fonts/simsun.ttc";
private static final String WIN_FONT_HEI = "C:/Windows/Fonts/simhei.ttf";
private static final String LINUX_FONT_SUN = "/usr/share/fonts/my_fonts/simsun.ttc";
private static final String LINUX_FONT_HEI = "/usr/share/fonts/my_fonts/STZHONGS.TTF";

xhtmlrenderer把html转换成pdf打印问题

标签:

原文地址:http://www.cnblogs.com/gmq-sh/p/5481063.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!