首页 > Web开发 > 详细

xhtmlrenderer把html转换成pdf打印问题

时间:2016-05-11 12:51:23      阅读:1029      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!