我使用 PDFBox 构建 PDF。我也有可见的签名。我写了一些这样的文字:
...
builderSting.append("Tm\n");
builderSting.append(" /F1 " + fontSize + "\n");
builderSting.append("Tf\n");
builderSting.append("(hello world)");
builderSting.append("Tj\n");
builderSting.append("ET");
...
PDStream stream= ...;
stream.createOutputStream().write(builder.toString().getBytes("ISO-8859-1"));
一切正常。但是如果我在builderString中写了一些unicode字符,就会有“???”而不是文本。
这是示例 PDF:链接在这里
问题 1)当我看到 PDF 结构时,有问号而不是文本。是的。而且我不知道如何用 unicode 字符编写?
9 0 obj
<<
/Type /XObject
/Subtype /Form
/BBox [100 50 0 0]
/Matrix [1 0 0 1 0 0]
/Resources <<
/Font 11 0 R
/XObject <<
/img0 12 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
/FormType 1
/Length 13 0 R
>>
stream
q 93.70079 0 0 50 0 0 cm /img0 Do Q
BT
1 0 0 1 93.70079 25 Tm
/F1 2
Tf
(????)Tj
ET
endstream
endobj
我有 Encoding WinAsciEncoding 的字体。我可以在 pdfbox 中使用另一种编码吗?
PDFont font = PDTrueTypeFont.loadTTF(template, new File("//fontName.ttf"));
font.setFontEncoding(new WinAnsiEncoding());
问题 2)我在 PDF 中嵌入了字体。但是文本不是用这种字体写的(在可见的签名矩形中)。为什么?
问题 3) 当我删除字体时,文本仍然存在(当文本是英文时)。默认字体是什么? /F1 - 这是第一种字体?
问题 4)如何计算可见签名中文本的宽度?有任何想法吗?