Visitar URL original
DOC: CMaps (#811) · py-pdf/pypdf@6729b80 · GitHub
Skip to content

Commit 6729b80

Browse files
authored
DOC: CMaps (#811)
1 parent 7541047 commit 6729b80

3 files changed

Lines changed: 66 additions & 1 deletion

File tree

‎docs/dev/cmaps.md‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# CMaps
2+
3+
Looking at the cmap of "crazyones":
4+
5+
```bash
6+
pdftk crazyones.pdf output crazyones-uncomp.pdf uncompress
7+
```
8+
9+
You can see this:
10+
11+
```text
12+
begincmap
13+
/CMapName /T1Encoding-UTF16 def
14+
/CMapType 2 def
15+
/CIDSystemInfo <<
16+
/Registry (Adobe)
17+
/Ordering (UCS)
18+
/Supplement 0
19+
>> def
20+
1 begincodespacerange
21+
<00> <FF>
22+
endcodespacerange
23+
1 beginbfchar
24+
<1B> <FB00>
25+
endbfchar
26+
endcmap
27+
CMapName currentdict /CMap defineresource pop
28+
```
29+
30+
## codespacerange
31+
32+
A codespacerange maps a complete sequence of bytes to a range of unicode glyphs.
33+
It defines a starting point:
34+
35+
```text
36+
1 beginbfchar
37+
<1B> <FB00>
38+
```
39+
40+
That means that `1B` (Hex for 27) maps to the unicode character [`FB00`](https://unicode-table.com/en/FB00/) - the ligature ff (two lowercase f's).
41+
42+
The two numbers in `begincodespacerange` mean that it starts with an offset of
43+
0 (hence from `1B ➜ FB00`) upt to an offset of FF (dec: 255), hence 1B+FF = 282
44+
➜ [FBFF](https://www.compart.com/de/unicode/U+FBFF).
45+
46+
Within the text stream, there is
47+
48+
```text
49+
(The)-342(mis\034ts.)
50+
```
51+
52+
`\034 ` is octal for 28 decimal.

‎docs/dev/pdf-format.md‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ startxref 1234
8484

8585
Let's go through it:
8686

87-
* `trailer <<` indicates that the *trailer dictionary` starts. It ends with `>>`.
87+
* `trailer <<` indicates that the *trailer dictionary* starts. It ends with `>>`.
8888
* `startxref` is a keyword followed by the byte-location of the `xref` keyword.
8989
As the trailer is always at the bottom of the file, this allows readers to
9090
quickly find the xref table.
@@ -99,3 +99,15 @@ Table 3.13 of the PDF Reference 1.7, e.g. `/Root` and `/Size` (both are required
9999
* `R` is the keyword that indicates that the object is a reference to the
100100
catalog dictionary.
101101
* `/Size` (integer) contains the total number of entries in the files xref table.
102+
103+
104+
## Reading PDF files
105+
106+
Most PDF files are compressed. If you want to read them, first uncompress them:
107+
108+
```bash
109+
pdftk crazyones.pdf output crazyones-uncomp.pdf uncompress
110+
```
111+
112+
Then rename `crazyones-uncomp.pdf` to `crazyones-uncomp.txt` and open it in
113+
our favorite IDE / text editor.

‎docs/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ You can contribute to `PyPDF2 on Github <https://github.com/py-pdf/PyPDF2>`_.
5454

5555
dev/intro
5656
dev/pdf-format
57+
dev/cmaps
5758

5859
.. toctree::
5960
:caption: About PyPDF2

0 commit comments

Comments
 (0)