简体   繁体   English

在Itext中修改现有PDF的字体

[英]Modify the font of existing PDF in Itext

Can I modify the font of existing PDF. 我可以修改现有PDF的字体吗? I've some Type 3 (Custom) fonts with out any font descriptor. 我有一些Type 3(自定义)字体,没有任何字体描述符。 I would like to replace those to some meaningful Font. 我想将它们替换为一些有意义的字体。 How can I do this using Itext or PDFBox ? 如何使用Itext或PDFBox做到这一点?

A Type3 font is also known as a user defined font . Type3字体也称为用户定义字体 Characters such as a , b , c ,... are mapped to glyphs that are defined by a person. 诸如abc ,...之类的字符映射到人定义的字形。 For instance a corresponds with the Apple logo, b corresponds with a glyph shaped as a banana, c looks like a coconut. 例如, a对应于Apple徽标, b对应于形状为香蕉的字形, c看起来像椰子。

  • The shape of the apple, banana, coconut,... is stored in the PDF using PDF syntax. 苹果,香蕉,椰子等的形状使用PDF语法存储在PDF中。 A PDF viewer such as Adobe Reader can draw the apple, banana, coconut,... by executing the font program that in this case consists of PDF path-constructing and path-painting operators and operands. PDF查看器(如Adobe Reader)可以通过执行字体程序绘制苹果,香蕉,椰子...,在这种情况下, 字体程序由PDF路径构造和路径绘制运算符及操作数组成。
  • A PDF viewer doesn't have the intelligence to recognize these shapes as being the representation of an apple, banana, coconut,... A PDF viewer only knows that the user mapped these glyphs to characters such as a , b , c ,... See also my answer to the question Why can't I extract text added using a Type3 font correctly? PDF查看器没有智能将这些形状识别为苹果,香蕉,椰子等的代表。PDF查看器仅知道用户将这些字形映射到诸如abc等字符。 ..另请参阅我对以下问题的回答: 为什么我不能正确提取使用Type3字体添加的文本?

Sometimes, people will match characters and glyphs, the way I did when I created a Type3 font for the iText logo: read Creating the iText logo witha Type3 font . 有时,人们会匹配字符和字形,就像我为iText徽标创建Type3字体时所做的那样:请阅读使用Type3字体创建iText徽标 However you shouldn't count on that. 但是,您不应指望这一点。 Any character can be mapped to any glyph. 任何字符都可以映射到任何字形。

Now that you know this, you should understand that you're trying to achieve something that is impossible. 现在,您已经知道了这一点,您应该了解,您正在尝试实现一些不可能的事情。 Suppose that you have a PDF with a Type3 font where the a character corresponds with an apple, the b character with a banana and the c character with a coconut, it won't be possible to automatically replace such a user-defined font with a custom encoding with another "normal" font that doesn't know how to draw apples, bananas and coconuts, and that uses a completely different encoding. 假设您有一个带有Type3字体的PDF,其中a字符对应一个苹果, b字符对应一个香蕉, c字符对应一个椰子,那么将无法自动用a替换这种用户定义的字体。使用另一种“普通”字体进行自定义编码 ,该字体不知道如何绘制苹果,香蕉和椰子,并且使用完全不同的编码。

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

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