简体   繁体   English

Pdfbox-找不到PDType0Font.load的符号

[英]Pdfbox - Cannot find symbol for PDType0Font.load

I have been attempting to solve this issue for a while. 我已经尝试解决这个问题一段时间了。 I have the latest PDFBox (2.0.7) and FontBox (2.0.7) for my program, and yet no matter what I do, I am getting the same compilation error. 我的程序具有最新的PDFBox(2.0.7)和FontBox(2.0.7),但是无论我做什么,我都会遇到相同的编译错误。

Within this class, here are my relevant imports: 在本课程中,这是我的相关导入:

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont;
import org.apache.pdfbox.pdmodel.font.PDType0Font;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.apache.pdfbox.pdmodel.common.PDRectangle;

I am attempting to set the font with the following sample: 我正在尝试使用以下示例设置字体:

PDDocument pdfDoc = new PDDocument();
PDPage page = new PDPage();
pdfDoc.addPage(page);

PDPageContentStream contents = new PDPageContentStream(pdfDoc, page);
PDFont font = PDType0Font.load(pdfDoc, new File("/path/to/font/Roboto-Regular.ttf"));
contents.setFont(font, 20);

Unfortunately, as I have stated, I get the following compilation error every time: 不幸的是,正如我所说,每次都会出现以下编译错误:

 error: cannot find symbol
 PDFont font = PDType0Font.load(pdfDoc, new File("/path/to/font/Roboto-Regular.ttf"));
 symbol:   method load(PDDocument,File)
 location: class PDType0Font

I have looked at the Javadocs multiple times, I have opened up the JAR file to confirm that that method is there (it is), and I have tried other things such as initializing the "font" as an instance of PDType0Font instead of the interface PDFont. 我已经多次看过Javadocs,我打开了JAR文件以确认该方法是否存在,并且我尝试了其他方法,例如将“ font”初始化为PDType0Font的实例而不是接口。 PDFont。 Same error. 同样的错误。 I have tried importing every single JAR the website offers for 2.0.7. 我尝试导入网站为2.0.7提供的每个JAR。 (Preflight, xmpbox, pdfbox-tools, pdfbox-debugger) and I still get the same error. (Preflight,xmpbox,pdfbox-tools,pdfbox-debugger),我仍然遇到相同的错误。 I have tried importing every single class from the pdmodel and pdmodel.font packages. 我尝试从pdmodel和pdmodel.font包中导入每个类。 Same error. 同样的错误。 Everything else works fine - it is just this one particular method. 其他所有东西都可以正常工作-这只是一种特定的方法。 Initially I had used PDTrueTypeFont instead of PDType0Font and it was just fine. 最初,我使用PDTrueTypeFont代替PDType0Font,这很好。 But I have to switch to PDType0Font due to foreign characters. 但是由于外来字符,我不得不切换到PDType0Font。

EDIT: Solved. 编辑:解决。 It turns out an outdated Tika JAR in my classpath was creating a conflict and reverting PDFBox to version 1.8.13. 原来我的类路径中的过时的Tika JAR正在产生冲突,并将PDFBox还原到1.8.13版。

This issue has been solved. 此问题已得到解决。 It turns out there was a conflict in my classpath. 事实证明,我的课程路径有冲突。 I had a very outdated Tika JAR that had PDFBox 1.8 within it, so I have updated Tika to the most recent version, and no longer have issues. 我有一个非常过时的Tika JAR,其中包含PDFBox 1.8,所以我已经将Tika更新到最新版本,不再有问题。 Thank you to Tilman Hausherr who suggested the solution. 感谢Tilman Hausherr建议的解决方案。

Could it be that there's an old .jar file in your class path? 可能是您的类路径中有一个旧的.jar文件吗? Try adding Exception e = new COSVisitorException(new Exception());. 尝试添加异常e = new COSVisitorException(new Exception());。 If that one works, then it means you have an 1.8 version in your classpath (and you shouldn't!) 如果该方法有效,则表明您的类路径中有一个1.8版本(您不应该!)

Pdfbox - Cannot find symbol for PDType0Font.load Pdfbox-找不到PDType0Font.load的符号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM