PDFBox填充表单时嵌入的字体无法正常工作。

huangapple go评论67阅读模式
英文:

PDFBox Embeded fonts not working when filling form

问题

我使用 field.setValue 填写表格。然而,即使PDF文档中嵌入了字体,无论是哪种类型的字体,我都会收到错误消息 "is not available in this font's encoding: WinAnsiEncoding"。请注意,这种情况发生在中文或俄文字符中。

英文:

I fill forms with field.setValue. However even though PDF document has embedded fonts in it, I am getting error "is not available in this font's encoding: WinAnsiEncoding" no matter which type of font it is. Note that this is happening for chinese or russian characters.

答案1

得分: 2

你的PDF文档可能包含嵌入的字体,但显然它们是使用WinAnsiEncoding嵌入的。

WinAnsiEncoding基本上包含了Latin-15字符,因此它适用于"西欧"语言(参见维基百科关于此的文章),尤其不适用于Cyrillic或CJK语言。

因此,如果您想要在使用PDFBox填充表单字段时插入中文或俄文字符,您必须要么事先使用适当的编码将字体嵌入到您的PDF中,要么在设置表单字段值之前使用PDFBox替换嵌入的字体,例如参考此答案

英文:

Your PDF documents may have embedded fonts but they apparently have been embedded with an Encoding value WinAnsiEncoding.

WinAnsiEncoding contains essentially the Latin-15 characters, so it is intended for “Western European” languages (see the Wikipedia article on this) and in particular neither for Cyrillic nor for CJK languages.

If you want to fill chinese or russian characters into form fields using PDFBox, therefore, you have to

  • either embed a font into your PDF using an appropriate encoding beforehand

  • or replace the embedded font with PDFBox right before setting the form field value, see for example this answer.

huangapple
  • 本文由 发表于 2020年8月20日 00:28:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/63491246.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定