目录
FontCreator实现字库合并_东风wangjk的博客-优快云博客_fontcreator合并字体
上下标展示问题
在生成PDF的时候,自己百度搜的上下标以及特殊符号正常存入数据库,但是PDF上面没有展示,这是因为所使用的的字体包中不包含上下标
数据库中:
PDF中:
D
D
D
如上下标没有展示
在windows字符集下有字符集segoeuisl.ttf 可以正常显示,目录为C:\Windows\Fonts
因此对于需要特殊显示的字符可以用这个字体测试: windows下测试代码为
BaseFont specialChinese = BaseFont.createFont("C:\\Windows\\Fonts\\segoeuisl.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
specialFont = new Font(specialChinese, 10, Font.NORMAL);
但是使用segoeuisl.ttf字体又没法展示中文
如果想要同时展示上下标和中文,我们需要将字体合并,将segoeuisl.ttf和simfang.ttf(Windows下的仿宋)进行合并
下面有我合并好的字体,下载就可以立即使用
合并后的字体下载:https://pan.baidu.com/s/1IZz8bAsMITtuknVTvvy52g
提取码:1111
如何合并?
我使用的是字体合并工具 FontCreator.exe
合并工具 FontCreator.exe百度网盘链接: https://pan.baidu.com/s/12PRO-SZsQxGlRdNinnHUIA
提取码:1111
合并教程:
FontCreator实现字库合并_东风wangjk的博客-优快云博客_fontcreator合并字体
itextpdf自定义上下标
如果一个上下标百度也搜索不到该如何在PDF上展示,可以使用以下方法
public void createPdf(String dest) throws IOException, DocumentException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(dest));
document.open();
Font small = new Font(FontFamily.HELVETICA, 6);
Chunk st = new Chunk("st", small);
st.setTextRise(7);
Chunk nd = new Chunk("nd", small);
nd.setTextRise(7);
Chunk rd = new Chunk("rd", small);
rd.setTextRise(7);
Chunk th = new Chunk("th", small);
th.setTextRise(7);
Paragraph first = new Paragraph();
first.add("The 1");
first.add(st);
first.add(" of May");
document.add(first);
Paragraph second = new Paragraph();
second.add("The 2");
second.add(nd);
second.add(" and the 3");
second.add(rd);
second.add(" of June");
document.add(second);
Paragraph fourth = new Paragraph();
fourth.add("The 4");
fourth.add(rd);
fourth.add(" of July");
document.add(fourth);
document.close();
}
itextpdf官网有很多示例,基本上你的需求例子都有
官方所有示例地址:https://kb.itextpdf.com/home/it5kb/examples
官方上下标示例地址:How to introduce superscript?