JAVA中pdf转图片的几种方法(四) html内容字体设置
作者:互联网
字体处理
注意:(seguisym.ttf" ,"simsun.ttc","simfang.ttf","simhei.ttf 字体需要在网上下载,本人没有尝试)
html内容字体设置,可以处理中文乱码,内容重叠,字体大小,字体颜色等
package com.hundsun.cooas.manage.sec.util; import com.itextpdf.text.BaseColor; import com.itextpdf.text.Font; import com.itextpdf.tool.xml.XMLWorkerFontProvider; import java.io.File; import java.util.Set; public class PdfFont extends XMLWorkerFontProvider { //新增PDF字体:特殊字符、宋体、仿宋、黑体 public String[] fonts = { "seguisym.ttf" ,"simsun.ttc","simfang.ttf","simhei.ttf"}; public PdfFont() { super(XMLWorkerFontProvider.DONTLOOKFORFONTS); //获取资源文件字体 String path = EnvironmentUtils.getWebClassPath()+"fonts"+ File.separator; // 注册字体 for (String font : fonts) { this.register(path+font); } } @Override public Font getFont(String fontname, String encoding, boolean embedded, float size, int style, BaseColor color) { //Set<String> fonts2 = this.getRegisteredFonts(); //获取注册字体 String font = fontname; if(font==null){ font = "宋体"; } if ("".equals(font)) { font = "segoe ui symbol";// 特殊字符 } if(size<=0){ size=10.5f; } return super.getFont(font, encoding, embedded, size, style, color); } } |
原文链接:https://blog.csdn.net/jianjun2114/article/details/80239138
标签:JAVA,String,html,字体,import,pdf,font,com,ttf 来源: https://www.cnblogs.com/zxy-come-on/p/15458395.html