gpt4 book ai didi

pdf - 解码 PDF 文档中的 FlateDecoded 文本部分

转载 作者:行者123 更新时间:2023-12-02 02:17:30 24 4
gpt4 key购买 nike

使用 peepdf我正在分析两个简单的 pdf 文件。这两个文件都包含一行文本(“ZYXWVUTSRQQRSTUVWXYZ”)并且是在 Mac OS X 上创建的。

第一个文件是用 TextEdit 创建的。只有三个流,看第一个(使用 peepdf 自动解码)显示文本清晰。

PPDF> stream 4

q Q q 72 707.272 468 12.72803 re W n /Cs1 cs 0 sc q 0.9790795 0 0 -0.9790795 72 720
cm BT 0.0001 Tc 11 0 0 -11 5 10 Tm /TT1 1 Tf (ZYXWVUTSRQQRSTUVWXYZ) Tj ET
Q Q

第二个文件是用 MS Word 创建的。有四个流,但找不到解码文本。查看 Word 文档中的相应流并没有显示解码后的字符串:

PPDF> stream 4

q Q q 18 40 576 734 re W n /Cs1 cs 0 0 0 sc q 0.24 0 0 0.24 90 708.72 cm BT
-0.0004 Tc 50 0 0 50 0 0 Tm /TT2 1 Tf [ (!") -1 (#) -1 ($) -1 (%&'\() -1 (\))
-1 (*) -1 (*) -1 (\)) -1 (\() -1 ('&%$) -1 (#) -1 (") -1 (!) ] TJ ET Q q 0.24 0 0 0.24 239.168 708.72
cm BT 50 0 0 50 0 0 Tm /TT2 1 Tf (+) Tj ET Q Q

我不清楚字符串在文件中的位置或此流中的信息的含义。有什么见解吗?

最佳答案

It's not apparent to me where the string is in the file

通常您不会在内容流中看到明文,因为那里使用的编码不需要标准编码,没有 ASCII'ish。

[ (!") -1 (#) -1 ($) -1 (%&'\() -1 (\)) -1 (*) -1 (*) -1 (\)) -1 (\() -1 ('&%$) -1 (#) -1 (") -1 (!) ] TJ

此操作在其数组操作数中包含您的 ZYXWVUTSRQQRSTUVWXYZ,其中对某些字符对进行了一些字距调整。

它看起来像是使用从 33 (= 0x21 = '!') 开始的字节的临时编码。 '!'用于第一个需要的字形,Z,'"'用于第二个需要的字形 Y,' #' 表示第三个 X 等。您的测试字符串不仅以这些字符开头,而且以它们结尾,上面的数组也是如此,( !") -1 (#) ... (#) -1 (") -1 (!)

检查所用字体的定义 (TT2)。它可能(也可能不)包含帮助您解码此编码的信息。

or what the information in this stream means. Any insights?

要了解 PDF 内容流的内容,您应该阅读 PDF 规范的相关部分 ISO 32000-1 ,尤其是第 8 章图形和第 9 章文本

由于您的问题侧重于文本内容的识别,例如阅读第 9.10.2 节将字符代码映射到 Unicode 值:

A conforming reader can use these methods, in the priority given, to map a character code to a Unicode value. Tagged PDF documents, in particular, shall provide at least one of these methods (see 14.8.2.4.2, "Unicode Mapping in Tagged PDF"):

  • If the font dictionary contains a ToUnicode CMap (see 9.10.3, "ToUnicode CMaps"), use that CMap to convert the character code to Unicode.

  • If the font is a simple font that uses one of the predefined encodings MacRomanEncoding, MacExpertEncoding, or WinAnsiEncoding, or that has an encoding whose Differences array includes only character names taken from the Adobe standard Latin character set and the set of named characters in the Symbol font (see Annex D):

    a) Map the character code to a character name according to Table D.1 and the font’s Differences array.

    b) Look up the character name in the Adobe Glyph List (see the Bibliography) to obtain the corresponding Unicode value.

  • If the font is a composite font that uses one of the predefined CMaps listed in Table 118 (except Identity–H and Identity–V) or whose descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or Adobe-Korea1 character collection:

    a) Map the character code to a character identifier (CID) according to the font’s CMap.

    b) Obtain the registry and ordering of the character collection used by the font’s CMap (for example, Adobe and Japan1) from its CIDSystemInfo dictionary.

    c) Construct a second CMap name by concatenating the registry and ordering obtained in step (b) in the format registry–ordering–UCS2 (for example, Adobe–Japan1–UCS2).

    d) Obtain the CMap with the name constructed in step (c) (available from the ASN Web site; see the Bibliography).

    e) Map the CID obtained in step (a) according to the CMap obtained in step (d), producing a Unicode value.

NOTE Type 0 fonts whose descendant CIDFonts use the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or Adobe-Korea1 character collection (as specified in the CIDSystemInfo dictionary) shall have a supplement number corresponding to the version of PDF supported by the conforming reader. See Table 3 for a list of the character collections corresponding to a given PDF version. (Other supplements of these character collections can be used, but if the supplement is higher-numbered than the one corresponding to the supported PDF version, only the CIDs in the latter supplement are considered to be standard CIDs.)

If these methods fail to produce a Unicode value, there is no way to determine what the character code represents in which case a conforming reader may choose a character code of their choosing.

编辑:关于评论

One of the objects gave some font info. It is 'JJOWGO+Cambria' and references object 16 as the 'font file' which was also unreadable. I'll review the manual. Can't find anything online about 'JJOWGO'.

您不会找到任何关于 JJOWGO 的具体信息,因为它很可能是一个以 Cambria 为前缀的随机键序列,表明并非嵌入了所有该字体,而只是嵌入了一个子集.比照。 ISO 32000-1 的第 9.6.4 节字体子集 :

PDF documents may include subsets of Type 1 and TrueType fonts. The font and font descriptor that describe a font subset are slightly different from those of ordinary fonts. These differences allow a conforming reader to recognize font subsets and to merge documents containing different subsets of the same font. (For more information on font descriptors, see 9.8, "Font Descriptors".)

For a font subset, the PostScript name of the font—the value of the font’s BaseFont entry and the font descriptor’s FontName entry— shall begin with a tag followed by a plus sign (+). The tag shall consist of exactly six uppercase letters; the choice of letters is arbitrary, but different subsets in the same PDF file shall have different tags.

EXAMPLE EOODIA+Poetica is the name of a subset of Poetica®, a Type 1 font.

 <<
/FontBBox [ -1475 -2463 2867 3117 ]
/StemV 0
/FontFile2 16 0 R
/Descent -222
/XHeight 467
/Flags 4
/Ascent 950
/FontName /JJOWGO+Cambria
/Type /FontDescriptor
/ItalicAngle 0
/AvgWidth 615
/MaxWidth 2919
/CapHeight 667
>>

这个字体描述符不包含明显的编码信息。查看实际的 Font 字典并查找 ToUnicode 条目,参见。上文第 9.10.2 节的引述。

关于pdf - 解码 PDF 文档中的 FlateDecoded 文本部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22446637/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com