Itext7的字体导入

来源:互联网 发布:hiddns域名注册 编辑:程序博客网 时间:2024/06/06 06:30

这是关于itext7导出PDF的使用其他的字体的方法

<dependency>        <groupId>com.itextpdf</groupId>        <artifactId>kernel</artifactId>        <version>7.0.2</version>    </dependency>    <dependency>        <groupId>com.itextpdf</groupId>        <artifactId>io</artifactId>        <version>7.0.2</version>    </dependency>    <dependency>        <groupId>com.itextpdf</groupId>        <artifactId>layout</artifactId>        <version>7.0.2</version>    </dependency>    <dependency>        <groupId>com.itextpdf</groupId>        <artifactId>forms</artifactId>        <version>7.0.2</version>    </dependency>    <dependency>        <groupId>com.itextpdf</groupId>        <artifactId>pdfa</artifactId>        <version>7.0.2</version>    </dependency>    <dependency>        <groupId>com.itextpdf</groupId>        <artifactId>pdftest</artifactId>        <version>7.0.2</version>    </dependency>    <dependency>    <groupId>com.itextpdf</groupId>    <artifactId>font-asian</artifactId>    <version>7.0.2</version>    </dependency>
这个是itext7上的引用的maven的依赖,需要的话可以去官网找更详细的iText官网

因为公司的需要在,字体上不能使用itext上自带的字体,需要导入其他的字体包  在这一仿宋为例(simfang.ttf)
我是将这个字体包放在resource下面的,使用下面的代码来加载字体包
InputStream inputStream = ItextPDFExportUtil.class.getResourceAsStream("/simfang.ttf"); font = PdfFontFactory.createFont(IOUtils.toByteArray(inputStream), PdfEncodings.IDENTITY_H, false);

这样就可以实现加载其他的字体


原创粉丝点击