我试图解析现有的pdf文件,但它失败了,出现了damagedfontexception。我看了pdf,它使用的是arial字体。所以我现在正在尝试添加arial字体,这是我现在得到的错误。
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/fontbox/ttf/TTFParser
at org.apache.pdfbox.pdmodel.font.PDType0Font.load(PDType0Font.java:147)
at org.apache.pdfbox.examples.interactive.form.FillFormField.main(FillFormField.java:54)
Caused by: java.lang.ClassNotFoundException: org.apache.fontbox.ttf.TTFParser
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 2 more
我修改了pdfbox示例中现有的fillformfield类,并将arial文本字段添加到测试pdf中,并且能够重现错误。
下面是我添加的代码:
PDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm();
acroForm.getDefaultResources().put(
COSName.getPDFName("Arial"),
PDType0Font.load(pdfDocument, new File("src/main/resources/org/apache/pdfbox/Arial.ttf")));
我做错了什么?我的主要目标是只填写文档中的表格,就这样。
更新:
这个 DamageFontException
在示例中修改现有pdf时发生
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/fontbox/type1/DamagedFontException
at org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:76)
at org.apache.pdfbox.pdmodel.PDResources.getFont(PDResources.java:143)
at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.validateAndEnsureAcroFormResources(AppearanceGeneratorHelper.java:150)
at org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.<init>(AppearanceGeneratorHelper.java:111)
at org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:261)
at org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:210)
at org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:218)
at org.apache.pdfbox.examples.interactive.form.FillFormField.main(FillFormField.java:87)
Caused by: java.lang.ClassNotFoundException: org.apache.fontbox.type1.DamagedFontException
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 8 more
暂无答案!
目前还没有任何答案,快来回答吧!