Apache PDFBox 3.0字体使用介绍
豆豆 2023-09-15 16:51:23 4966人已围观
一、使用Apache PDFBox默认字体
public void createPDF(String filePath, String conttext) {
try {
PDDocument document =new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.beginText();
//设置pdfbox默认字体(此字体不支持中文)
PDType1Font font2 =new PDType1Font(Standard14Fonts.FontName.COURIER);
contentStream.setFont(font2, 12);
contentStream.newLineAtOffset(100, 700);
contentStream.showText(conttext);
contentStream.endText();
contentStream.close();
document.save(filePath);
document.close();
System.out.println("PDF created successfully.");
} catch (IOException e) {
e.printStackTrace();
}
}二、使用字体文件加载字体
我这里是以pdfbox.jar文件中自带的一个字体ttf文件作为开发的例子,如果你喜欢其他的字体也可以下载字体文件后用类似的方法加载使用
public void createPDF(String filePath, String conttext) {
try {
PDDocument document =new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.beginText();
//设置pdfbox自带字体文件(此字体不支持中文)
PDFont font = PDType0Font.load(document, this.getClass().getResourceAsStream(
"/org/apache/pdfbox/resources/ttf/LiberationSans-Regular.ttf"));
contentStream.setFont(font, 12);
contentStream.newLineAtOffset(100, 700);
contentStream.showText(conttext);
contentStream.endText();
contentStream.close();
document.save(filePath);
document.close();
System.out.println("PDF created successfully.");
} catch (IOException e) {
e.printStackTrace();
}
}三、常见字体文件下载
分享到:
编辑发布时间:2023-09-15 16:51:23

备付金存管银行是指可以为支付机构办理客户备付金的跨行收付业务,并负责对支付机构存放在所有备付金银行的客户备付金信息进行归集、核对与监督的备付金银行。(支付机构客
最近有一套生产系统的数据库CPU老是偏高,发现闲时也在40%-60%左右,感觉很不正常,决定优化一下,在这
首先需要知道什么叫一元购? 就是你支付一元后获得一个购物资格,有的叫抽