本文共 592 字,大约阅读时间需要 1 分钟。
使用iText操作pdf编辑内容时抛出异常,日记如下所示
Exception in thread “main” java.lang.NullPointerException: Font and size must be set before writing any text
at com.itextpdf.text.pdf.PdfContentByte.showText2(PdfContentByte.java:2004) at com.itextpdf.text.pdf.PdfContentByte.showText(PdfContentByte.java:2019)
在编辑pdf之前没有定义字体font。只要在编辑之前定义好font就不会抛出这个错
BaseFont Chinese = BaseFont.createFont("C:\\Windows\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, .EMBEDDED); overContent.setFontAndSize(Chinese, 10F);
转载地址:http://ajvzb.baihongyu.com/