我正在使用itext库将html转换为pdf。我可以正确转换,但不能添加字体。我的转换代码在这里
Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
cfg.setObjectWrapper(new DefaultObjectWrapper(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS));
Template t = new Template("templateName", new StringReader(templateHTML), cfg);
Writer out = new FileWriter(new File(TARGET + documentName + ".html"));
t.process(model, out);
out.close();
ConverterProperties properties = new ConverterProperties();
properties.setBaseUri(TARGET);
File output = new File(TARGET + documentName + ".pdf");
FontProvider fontProvider = new DefaultFontProvider();
FontProgram fontProgram = FontProgramFactory.createFont(FONT);
fontProvider.addFont(fontProgram);
properties.setFontProvider(fontProvider);
HtmlConverter.convertToPdf(
new FileInputStream(TARGET + documentName + ".html"),
new FileOutputStream(TARGET + documentName + ".pdf"),
properties);
我的目标和字体在这里
public static String TARGET = "target/classes/documentsTemplate/";
public static final String FONT = "./src/main/resources/fonts/special.ttf";
我也试着像这样给html添加字体
* {
font-family: myFirstFont;
src: local("C:/font/special.ttf");
}
.text-font {
font-family: "myFirstFont";
}
1条答案
按热度按时间mitkmikd1#
我决定用这个密码。
但我不能使我的字体加粗