繁体   English   中英

如何以正确的嵌入字体显示PDF文本

[英]How to display PDF text with the correct embedded font

我目前正在编写PDF阅读器,但无法显示带有嵌入式字体的文本。

我以为Type 1字体的字体文件流将包含带有信息的后记,该信息如何显示每个字形。

我尝试对流进行平铺编码,但结果不可读,而且似乎毫无意义。

 private static byte[] DecodeFlateDecodeData(byte[] data)
        {
            MemoryStream outputStream;
            using (outputStream = new MemoryStream())
            {
                using (var compressedDataStream = new MemoryStream(data))
                {
                    // Remove the first two bytes to skip the header (it isn't recognized by the DeflateStream class)
                    compressedDataStream.ReadByte();
                    compressedDataStream.ReadByte();

                    var deflateStream = new DeflateStream(compressedDataStream, CompressionMode.Decompress, true);

                    var decompressedBuffer = new byte[1024];
                    int read;
                    while ((read = deflateStream.Read(decompressedBuffer, 0, decompressedBuffer.Length)) != 0)
                    {
                        outputStream.Write(decompressedBuffer, 0, read);
                    }
                    outputStream.Flush();
                    compressedDataStream.Close();
                }
                return outputStream.ToArray();
            }
        }

来源: 使用某些实用程序或脚本将嵌入式PDF字体提取到外部ttf文件

我期待这样的事情

%!FontType1-1.0: Symbol 001.003
%%CreationDate: Thu Apr 16 1987
%%VMusage: 27647 34029
% Copyright (c) 1985, 1987 Adobe Systems
% Incorporated. All rights reserved.
11 dict begin
/FontInfo 8 dict dup begin
/version (001.003) readonly def
/FullName (Symbol) readonly def
/FamilyName (Symbol) readonly def
/Weight (Medium) readonly def
/ItalicAngle 0 def
/isFixedPitch false def
/UnderlinePosition -98 def
/UnderlineThickness 54 def
end readonly def
/FontName /Symbol def
.
.
.
cleartomark

如第11页的Type 1 参考中所见。

还是我从根本上误解了这里的东西?

如果原始文件是Type1C而不是Type1(子类型),则会发生这种情况。

暂无
暂无

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

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