Apache FOP:在 PDF 中显示 UTF-8 字符(不嵌入?)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1302528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:05:18  来源:igfitidea点击:

Apache FOP: Displaying UTF-8 Characters in PDF (without embed?)

apachepdfutf-8fontsapache-fop

提问by Tyler D

I'm trying to use FOP to export a PDF with UTF-8 characters, preferably without needing to embed the font.
The following code:

我正在尝试使用 FOP 导出带有 UTF-8 字符的 PDF,最好不需要嵌入字体。
以下代码:

<fo:block font="10pt Helvetica" text-align="justify" space-after="10pt" space-before="8pt" keep-with-previous="auto" keep-together.within-page="auto"> 
  <fo:block font-weight="bold" color="gray">Summary</fo:block>
  <fo:block text-indent="1em" keep-with-previous="always">
    <fo:block text-indent="1em" space-before="4pt">
      <fo:block text-indent="1em" space-before="4pt">私はガラスを食べられます。それは私を傷つけません
      </fo:block>
    </fo:block>
  </fo:block>
</fo:block>

produces #################### in the PDF. I'm aware of the issue: http://xmlgraphics.apache.org/fop/faq.html#pdf-characters

在 PDF 中生成 ###################。我知道这个问题:http: //xmlgraphics.apache.org/fop/faq.html#pdf-characters

When I go under Document Properties->Fonts, the Helvetica font is listed with 'Encoding: ANSI'. Is there a way to change this?

当我进入“文档属性”->“字体”时,Helvetica 字体与“编码:ANSI”一起列出。有没有办法改变这种情况?

If I were embedding, what would be the best way to do so without having access to Helvetica.ttf? I've tried using DejaVuSans, but I end up with squares in place of the # signs.

如果我要嵌入,那么在无法访问 Helvetica.ttf 的情况下这样做的最佳方法是什么?我试过使用 DejaVuSans,但我最终用方块代替了 # 符号。

Note that this is not a one-time use from the command line (that would be a start), but an extension to an existing app. I'm trying to support UTF-8 characters without too much complexity.

请注意,这不是从命令行一次性使用(这将是一个开始),而是对现有应用程序的扩展。我正在尝试支持 UTF-8 字符而不会太复杂。

采纳答案by D.Shawley

AFAICT, the fonts included in the PDF specificationonly include characters from ISO-Latin-1. If you want a character that falls outside of those defined in Annex D: Character Sets and Encodings, then you are expected to embed the font.

AFAICT,PDF 规范中包含的字体仅包含 ISO-Latin-1 中的字符。如果您想要的字符不在Annex D: Character Sets and Encodings 中定义的字符范围内,那么您应该嵌入该字体。