如何获取字体数据以嵌入到 PDF 中?

How to obtain font data to embed in a PDF?

我的 MFC 应用程序创建了一个 PDF,现在我尝试嵌入字体,创建的 PDF 在 Foxit 中打开,Chrome,Windows 8 PDF Reader 但没有在 Acrobat 中没有。

我尝试用 this online validator 验证 pdf 文件,它说

The object's identity 6 doesn't match with the object's reference identity 5.

The embedded font program 'Candara' cannot be read.


我认为我嵌入它的方式是正确的

3 0 obj
<</Type /Font
    /Subtype /TrueType
    /BaseFont /Candara
    /FirstChar 0
    /LastChar 255
    /Widths 4 0 R
    /FontDescriptor 5 0 R
>>
endobj

5 0 obj
<<
    /Type /FontDescriptor
    /FontName /Candara
    /Flags 32
    /FontBBox [-700 -500 1800 1500]
    /ItalicAngle 0
    /Ascent 12
    /Descent -4
    /CapHeight 8
    /StemV 109
    /FontFile2 6 0 R
>>
endobj

6 0 obj
<<
    /Length 100376
    /Length1 100376
>>
stream
    ... font bytes ...
endstream
endobj


我相信我的问题是用

获得的字体数据
LONG ret = ::TTEmbedFont(pDC->GetSafeHdc(),
                    TTEMBED_TTCOMPRESSED, 
                    CHARSET_UNICODE,
                    &ulPrivStatus,
                    &ulStatus,
                    WriteEmbedProc,
                    lpvVecBytes,
                    nullptr,
                    0,
                    0,
                    nullptr);

我也试过使用TTEMBED_RAWTTEMBED_EMBEDEUDC



抱歉解释冗长且可能含糊不清,但我有点迷路了,

那么这是获取要嵌入的字体数据的正确方法吗?如果是,我应该对字体文件对象应用过滤器吗?

编辑: 我将我的应用程序更改为使用 GetFontData 字体文件的 returns 字节,根据我的研究,可以使用像这样,但我仍然无法在 Acrobat 中打开,在线验证站点仍然给我相同的错误消息。

link 到包含我的问题的示例 PDF。

谢谢,我们将不胜感激!

字体嵌入本身看起来不错。获取字体对象实际上存在一个较低级别的错误。

尝试使用 Xpdf 查看 PDF 时出现交叉引用错误 table:xref num 5 not found but needed, try to reconstruct<0a>

查看 PDF 末尾的交叉引用 table:

外部参照 0 10 0000000000 65535 楼 0000242485 00000 否 0000242426 00000 否 0000000016 00000 否 0000000155 00000 否 0000001081 00000 n % 错应该是0000241738 0000001081 00000 n<br> 0000241929 00000 否 0000242056 00000 否 0000242353 00000 否

实际错误在交叉引用 table 的第 6 行,其中包含对象 6 0 R 的字节偏移量,而不是 5 0 R

来自在线验证器 The object's identity 6 doesn't match with the object's reference identity 5. 的消息是由于在线验证器试图通过索引获取对象 5 0 R,但实际上获取的是对象 6 0 R.

需要修复此 PDF 的交叉引用 table。