Réduire la taille du fichier

Le même document écrit deux fois, en clair puis rangé, avec ce que pèse chacun et ce que le rangement a fait gagner.

JSON write_object_streams.json 95 lignes

Celui-ci n'est pas un programme. C'est la requête envoyée au serveur de documents : la même page, demandée par le réseau, par une application qui n'écrit pas une ligne de code PDF.

Cette demande écrit en toutes lettres les trois poids que la bibliothèque compte toute seule : ce que pèse le document en clair, ce que pèse le document rangé, et l'écart entre les deux. La bibliothèque les lit sur les deux fichiers qu'elle vient d'écrire, donc ils suivent tout ce qui entre dans un document ; ici ils sont tapés à la main, et il faudrait les retaper.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{
  "compression": {"object_streams": true},
  "items": [
    {
      "type": "text",
      "rect": {"llx": 60, "lly": 758.4, "urx": 535, "ury": 780},
      "content": ["What packing a document saves"],
      "font": "DejaVuSans",
      "font_size": 18
    },
    {
      "type": "text",
      "rect": {"llx": 60, "lly": 664, "urx": 535, "ury": 748},
      "content": ["A PDF is mostly dictionaries — the catalogue, the page tree, every page, every font, every annotation — and a dictionary is not a stream, so each one is written out in full and none of them is compressed.\nObject streams gather them into streams that are compressed together, and the table stating where every object lives becomes a stream too. The document a reader sees is the same one either way."],
      "font": "DejaVuSans",
      "font_size": 10,
      "leading": 14
    },
    {
      "type": "text",
      "rect": {"llx": 60, "lly": 622, "urx": 535, "ury": 636},
      "content": ["The document weighed here holds 24 pages of text, each with a heading of its own."],
      "font": "DejaVuSans",
      "font_size": 10,
      "leading": 14
    },
    {
      "type": "text",
      "rect": {"llx": 60, "lly": 586.8, "urx": 535, "ury": 600},
      "content": ["The same document, weighed twice"],
      "font": "DejaVuSans",
      "font_size": 11
    },

    {
      "type": "text",
      "rect": {"llx": 60, "lly": 562, "urx": 535, "ury": 574},
      "content": ["Spelled out"],
      "font": "DejaVuSans",
      "font_size": 10
    },
    {
      "type": "text",
      "rect": {"llx": 220, "lly": 562, "urx": 535, "ury": 574},
      "content": ["50 177 bytes"],
      "font": "DejaVuSans",
      "font_size": 10
    },
    {
      "type": "text",
      "rect": {"llx": 60, "lly": 542, "urx": 535, "ury": 554},
      "content": ["Packed"],
      "font": "DejaVuSans",
      "font_size": 10
    },
    {
      "type": "text",
      "rect": {"llx": 220, "lly": 542, "urx": 535, "ury": 554},
      "content": ["45 826 bytes"],
      "font": "DejaVuSans",
      "font_size": 10
    },
    {
      "type": "text",
      "rect": {"llx": 60, "lly": 522, "urx": 535, "ury": 534},
      "content": ["Saved"],
      "font": "DejaVuSans",
      "font_size": 10
    },
    {
      "type": "text",
      "rect": {"llx": 220, "lly": 522, "urx": 535, "ury": 534},
      "content": ["4 351 bytes"],
      "font": "DejaVuSans",
      "font_size": 10
    },

    {
      "type": "text",
      "rect": {"llx": 60, "lly": 444, "urx": 535, "ury": 486},
      "content": ["Packing this document saved 8 per cent of it. What it saves goes up with the number of pages, because a page costs a handful of dictionaries and dictionaries are what packing compresses."],
      "font": "DejaVuSans",
      "font_size": 10,
      "leading": 14
    },
    {
      "type": "text",
      "rect": {"llx": 60, "lly": 396, "urx": 535, "ury": 424},
      "content": ["This very file is packed, so a reader that opened it has read one of the two documents being weighed."],
      "font": "DejaVuSans",
      "font_size": 10,
      "leading": 14
    }
  ]
}