pdf - PDF 中的统一码

标签 pdf unicode utf-8 pdf-generation

我的程序根据要求生成相对简单的 PDF 文档,但我在处理 unicode 字符(例如汉字或奇怪的数学符号)时遇到问题。要在 PDF 中写入普通字符串,请将其放在括号中:

(something)

还可以选择使用八进制代码转义字符:

(\527)

但这最多只能包含 512 个字符。如何对更高位的字符进行编码或转义?我已经看到了对字节流和十六进制编码字符串的引用,但我读过的引用文献似乎都不愿意告诉我如何实际做到这一点。

<小时/>

编辑:或者,给我指出一个好的 Java PDF 库,它可以帮我完成这项工作。我目前使用的是 gnujpdf 的一个版本(我已经修复了其中的几个错误,因为原作者似乎已经擅离职守),它允许您针对 AWT 图形界面进行编程,并且理想情况下任何替换都应该这样做一样的。

替代方案似乎要么是 HTML -> PDF,要么是基于段落和框的编程模型,感觉非常像 HTML。 iText 就是后者的一个例子。这意味着重写我现有的代码,而且我不相信它们会给我同样的布局灵 active 。

<小时/>

编辑 2: 我之前没有意识到,但 iText 库有一个 Graphics2D API 并且似乎可以完美地处理 unicode,所以这就是我将使用的。虽然这不是所问问题的答案,但它为我解决了问题。

<小时/>

编辑 3: iText 对我来说工作得很好。我想这个教训是,当面对一些看似毫无意义的困难时,寻找比你更了解它的人。

最佳答案

在第 3 章的 PDF 引用中,他们是这样描述 Unicode 的:

Text strings are encoded in either PDFDocEncoding or Unicode character encoding. PDFDocEncoding is a superset of the ISO Latin 1 encoding and is documented in Appendix D. Unicode is described in the Unicode Standard by the Unicode Consortium (see the Bibliography). For text strings encoded in Unicode, the first two bytes must be 254 followed by 255. These two bytes represent the Unicode byte order marker, U+FEFF, indicating that the string is encoded in the UTF-16BE (big-endian) encoding scheme specified in the Unicode standard. (This mechanism precludes beginning a string using PDFDocEncoding with the two characters thorn ydieresis, which is unlikely to be a meaningful beginning of a word or phrase).

关于pdf - PDF 中的统一码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/128162/

相关文章:

python - 匹配任何语言的字母

ios - 清理格式错误的 UTF-8 数据

php - phpMyAdmin 中的西里尔字母编码 UTF8 - 文本出现乱码

python - 在 Python 中将 utf-8 转换为 latin-1

php - 带有特殊字符的文件名,如 "é"NOT FOUND

.net - 如何以编程方式构建 PDF/A 格式的 PDF

php - 使用 libreoffice 使用 --headless --convert-to 标志将 .doc(x) 转换为 PDF/A-1a 格式

javascript - 是否有可以将 JavaScript 插入现有 PDF 文件的 Ruby gem?

javascript - 使用 Extendscript 在 InDesign 中放置文件时指定编码

ios - 如何加载现有的PDF