我该如何解决这个pdfbox问题?
错误:找不到符号 PDFont 字体 = PDType1Font.HELVETICA_BOLD;
这是我得到的错误。我是使用 PDFBox 的新手,现在尝试写入 pdf 文件,我必须指定字体,但字体带来了错误。我正在终端中为那些不使用 IDE 的人进行编译。例如(java -cp commons-logging-1.2.jar:fontbox-3.0.0-alpha2.jar:pdfbox-3.0.0-alpha2.jar:pdfbox-tools-3.0.0-alpha2.jar:preflight-3.0.0 -alpha2.jar:xmpbox-3.0.0-alpha2.jar doc1.java)
error: cannot find symbol
PDFont font = PDType1Font.HELVETICA_BOLD;
This is the error am getting. Am new in using PDFBox and now am trying to write into a pdf file and I must specify the font but the font is bringing the error. I am compiling in terminal for those guys using IDE's am not. e.g (java -cp commons-logging-1.2.jar:fontbox-3.0.0-alpha2.jar:pdfbox-3.0.0-alpha2.jar:pdfbox-tools-3.0.0-alpha2.jar:preflight-3.0.0-alpha2.jar:xmpbox-3.0.0-alpha2.jar doc1.java)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请检查 PDFBox 3.0 迁移指南,但正如 @tilman-hausherr 所说,如果您是新开始使用 PDFBox,请使用 2.0.25,否则您会遇到其他问题,因为 PDFBox3 还不是稳定版本。
如果您一致使用此版本,请提供更多提示并添加您的代码。
删除了标准 14 字体的静态实例
标准 14 种字体的 PDType1Font 静态实例已被删除,因为底层 COSDictionary 不应该是不可变的,这导致了几个问题。
引入了 PDType1Font 的新构造函数来创建标准 14 字体。新的 Enum Standard14Fonts.FontName 是唯一的参数,它定义为其创建 PDType1Font 实例的标准 14 字体的名称。该实例不再是单例,必须在必要时重新创建,或者在合适的情况下由用户缓存。
https://pdfbox.apache.org/3.0/migration.html
Please Check PDFBox 3.0 Migration Guide but as @tilman-hausherr said if you are newly started using PDFBox use 2.0.25 otherwise you will have other problems because PDFBox3, is not a stable version yet.
If you are consistent to use this version, please provide more cues and also add your code.
Static instances for Standard 14 fonts removed
The static instances of PDType1Font for the standard 14 fonts were removed as the underlying COSDictionary isn't supposed to be immutable which led to several issues.
A new constructor for PDType1Font was introduced to create a standard 14 font. The new Enum Standard14Fonts.FontName is the one and only parameter and defines the name of the standard 14 font for which the instance of PDType1Font is created for. That instance isn't a singleton anymore and has to be recreated if necessary or cached by the user if suitable.
https://pdfbox.apache.org/3.0/migration.html