pdf语法

参考:

pdf格式分析 - 随笔分类 - 大黄蜂_001 - 博客园 (cnblogs.com)

一个简单的PDF文件结构的分析 - 简书 (jianshu.com)

推荐使用python处理:常用Python PDF库对比

总体结构

  • 文件头
  • xref:表查引用表
  • trailer:文件尾对象,总的对象
    • Info:文档信息(标签kv)
    • Root:目录Catalog对象
      • Pages:页面对象
        • PieceInfo:碎片信息(盲猜标准不统一的信息)
        • Count:页数
        • Kids:每一页的对象数组,每一个是Page
          • Resources:资源
          • MediaBox:像素大小
          • Annots
          • Contents
          • StructParents
          • Parent
          • Font字体
            • DescendantFonts:子字体
              • FontDescriptor:解码器
      • Outlines:总书签,+作为父书签才有,-作为子书签才有,可能同时作为父书签和子书签
        • +Count:子书签数量
        • +First:第一个书签
        • +Last:最后一个书签
        • -Parent:父书签
        • -Title:标题
        • -Dest:指向的位置
        • -Prev:上一个
        • -Next:下一个

下面是各个类的示例

文件头

%PDF-1.4
%����

xref

xref
0 130
0000000000 65535 f
0000000015 00000 n
0000000119 00000 n

trailer

trailer
<</Root 11 0 R 
/Info 2 0 R 
/Size 130
/ID[<A81AB50E4EDC5257EEA13CE7437A0F98><E75188B42A8B70D3D3BF0783DEAD60AB>]>>
startxref
198456
%%EOF

Info()

2 0 obj
<</Producer(PyPDF2)
/ModDate(D:20221012135616+08'00')>>
endobj

Root(Catalog类型)

11 0 obj
<</Type /Catalog
/Pages 1 0 R 
/Outlines 124 0 R 
/PieceInfo 127 0 R >>
endobj

PoeceInfo

127 0 obj
<</WPS_ICV 126 0 R >>
endobj

Pages(Pages类型)

1 0 obj
<</Type /Pages
/Count 8
/Kids[ 3 0 R  4 0 R  5 0 R  6 0 R  7 0 R  8 0 R  9 0 R  10 0 R ]>>
Kids(Page类型)
<</Type /Page
/Resources <</ProcSet [/PDF/Text/ImageB/ImageC/ImageI]/ExtGState<</G3 48 0 R >> /Font <</F4 87 0 R /F5 68 0 R /F6 43 0 R >> >>
/MediaBox[ 0 0 594.96 841.92]
/Annots[ 86 0 R  85 0 R  84 0 R  83 0 R  82 0 R  81 0 R  80 0 R  79 0 R ]
/Contents 78 0 R 
/StructParents 1
/Parent 1 0 R >>
Contents
78 0 obj
<</Filter/FlateDecode/Length 548>>stream
一堆二进制流乱码
endstream
Annots的某一项()
86 0 obj
<</Type /StructElem
/S /Link
/P 77 0 R
/K [<</Type /OBJR
/Obj 15 0 R
/Pg 2 0 R>>]
/ID (node00000260)>>
endobj
Font(字体)
63 0 obj
<</Type /Font
/Subtype /Type0
/BaseFont /HAAAAA+Consolas-Italic
/Encoding /Identity-H
/DescendantFonts[ 65 0 R ]
/ToUnicode 64 0 R >>
endobj
DescendantFonts(子字体,可能有误)
65 0 obj
<</Type /Font
/FontDescriptor 66 0 R 
/BaseFont /HAAAAA+Consolas-Italic
/Subtype /CIDFontType2
/CIDToGIDMap /Identity
/CIDSystemInfo <</Registry(Adobe) /Ordering(Identity) /Supplement 0>>
/W[ 0 373 549.805]
/DW 0>>
endobj

####### FontDescriptor(字体解码)

66 0 obj
<</Type /FontDescriptor
/FontName /HAAAAA+Consolas-Italic
/Flags 68
/Ascent 919.922
/Descent 250.977
/StemV 129.883
/CapHeight 638.184
/ItalicAngle -11
/FontBBox[ -365.723 -260.254 703.613 1011.23]
/FontFile2 67 0 R >>
endobj

Outlines(总书签)

124 0 obj
<</First 123 0 R 
/Last 128 0 R 
/Count 2>>
endobj
某一个子书签(不再有子书签)
128 0 obj
<</Parent 124 0 R 
/Prev 123 0 R 
/Title(3 ---\r)
/Dest[ 7 0 R /XYZ -165.82 489.55 1.25]>>
endobj
某一个子书签(有子书签)
123 0 obj
<</Parent 124 0 R 
/Title(bookmark001)
/Dest[ 4 0 R 
/XYZ -165.82 37.3253 1.25]
/Next 128 0 R 
/First 129 0 R 
/Last 129 0 R 
/Count 1>>
endobj

其他对象

URI链接

62 0 obj
<</Type /Annot
/Subtype /Link
/F 4/
Border [ 0 0 0]
/Rect [ 61.75 747.17 85.75 762.92]
/A <</Type/Action/S/URI/URI(https://www.baidu.com/)>>
/StructParent 100039>>
endobj

本地链接(dest直接写)

392 0 obj
<</Type /Annot
/Subtype /Link
/P 53 0 R /
F 4
/M(D:20221012150616+08'00')
/HighDpi false
/Rect[ 62.854 604.112 125.256 615.824]
/T(��T4�?��)
/Subj(Link)
/CreationDate(D:20221012150616+08'00')
/C [ 0 0 0]
/CA 1
/NM({68eab64b-71df-40d1-bdc3-663915f9a642})
/BS<</S/S/W 1>>
/A 393 0 R >>
endobj

本地链接(dest不直接写)

7 0 obj
<</Type /Annot
/Subtype /Link
/F 4
/Border[ 0 0 0]
/Rect[ 95.5 754.67 148 768.92]
/Dest /autocjs-heading-0
/StructParent 100000>>
endobj

74 0 obj
<</autocjs-heading-0 [48 0 R /XYZ 61.750004 777.92004 0]
其他标记点
>>
endobj
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值