write_linked_text.json

The JSON file of the “Links and marks on placed text” example. Links and marks hung on text the engine has already placed: a band behind a line, an underline, a boxed cell — every rectangle taken from what the layout and the table report afterwards, none of it measured by hand.

JSON 289 lines

This file is a request: an application sends it over the network to the server, which creates the PDF and sends it back. It makes the same page as the Rust and Python versions of this example. A request names every file it uses, never its content; the call carries the request and the files together. A font the server already holds, such as DejaVuSans, is named with nothing attached. Send the request to the address the API page gives.

This request writes out figures the library works out for itself: the pale band, the rule, the rectangle and the two clickable patches are named here as numbers, where the library measures them off the text it has just laid out. Both files paint the same rectangles, but changing the font would move the text here and leave the rectangles behind.

What this example is for

The hard part of putting a link on a word is not the link. It is knowing where that word ended up, on a page whose text was broken into lines by the layout rather than by you. Guess the rectangle and it stays right until somebody edits the sentence, changes the font, or opens the French version of the same document.

What this example shows

  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
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
{
  "items": [
    {
      "type": "text",
      "rect": {
        "llx": 70.0,
        "lly": 590.0,
        "urx": 525.0,
        "ury": 790.0
      },
      "content": [
        "Boxes over what the engine placed"
      ],
      "font": "DejaVuSans",
      "font_size": 18.0
    },
    {
      "type": "rect",
      "rect": {
        "llx": 70.0,
        "lly": 732.40576171875,
        "urx": 513.16357421875,
        "ury": 745.21044921875
      },
      "fill": [
        1.0,
        0.93,
        0.6
      ]
    },
    {
      "type": "text",
      "rect": {
        "llx": 70.0,
        "lly": 550.0,
        "urx": 525.0,
        "ury": 750.0
      },
      "content": [
        "The engine knows where every line and every cell lands, down to the point. This paragraph was flowed into a column, and the pale band was painted behind its first line from the box the engine reported, not measured by hand. The same boxes make a line clickable and draw a rule exactly under it."
      ],
      "font": "DejaVuSans",
      "font_size": 11.0,
      "leading": 15.0
    },
    {
      "type": "text",
      "rect": {
        "llx": 70.0,
        "lly": 455.0,
        "urx": 525.0,
        "ury": 655.0
      },
      "content": [
        "Read the terms at https://example.org/hqf-pdf/terms"
      ],
      "font": "DejaVuSans",
      "font_size": 12.0,
      "color": [
        0.0,
        0.2,
        0.8
      ]
    },
    {
      "type": "rect",
      "rect": {
        "llx": 70.0,
        "lly": 637.769921875,
        "urx": 387.53125,
        "ury": 638.369921875
      },
      "fill": [
        0.0,
        0.2,
        0.8
      ]
    },
    {
      "type": "table",
      "columns": {
        "widths": [
          {
            "points": 140.0
          },
          {
            "points": 315.0
          }
        ],
        "total": 455.0
      },
      "first": {
        "llx": 70.0,
        "lly": 410.0,
        "urx": 525.0,
        "ury": 610.0
      },
      "next": {
        "llx": 70.0,
        "lly": 410.0,
        "urx": 525.0,
        "ury": 610.0
      },
      "header": 1,
      "rules": [
        {
          "rule": "frame",
          "stroke": {
            "width": 0.8
          }
        },
        {
          "rule": "horizontal_other",
          "stroke": {
            "width": 0.25,
            "color": [
              0.75,
              0.75,
              0.75
            ]
          }
        }
      ],
      "rows": [
        {
          "cells": [
            {
              "content": [
                "Field"
              ],
              "font": "DejaVuSans",
              "font_size": 10.0,
              "padding": {
                "left": 6.0,
                "right": 6.0,
                "top": 4.0,
                "bottom": 4.0
              }
            },
            {
              "content": [
                "Value"
              ],
              "font": "DejaVuSans",
              "font_size": 10.0,
              "padding": {
                "left": 6.0,
                "right": 6.0,
                "top": 4.0,
                "bottom": 4.0
              }
            }
          ]
        },
        {
          "cells": [
            {
              "content": [
                "Product"
              ],
              "font": "DejaVuSans",
              "font_size": 10.0,
              "padding": {
                "left": 6.0,
                "right": 6.0,
                "top": 4.0,
                "bottom": 4.0
              }
            },
            {
              "content": [
                "hqf-pdf"
              ],
              "font": "DejaVuSans",
              "font_size": 10.0,
              "padding": {
                "left": 6.0,
                "right": 6.0,
                "top": 4.0,
                "bottom": 4.0
              }
            }
          ]
        },
        {
          "cells": [
            {
              "content": [
                "Licence"
              ],
              "font": "DejaVuSans",
              "font_size": 10.0,
              "padding": {
                "left": 6.0,
                "right": 6.0,
                "top": 4.0,
                "bottom": 4.0
              }
            },
            {
              "content": [
                "See the licence online"
              ],
              "font": "DejaVuSans",
              "font_size": 10.0,
              "padding": {
                "left": 6.0,
                "right": 6.0,
                "top": 4.0,
                "bottom": 4.0
              }
            }
          ]
        },
        {
          "cells": [
            {
              "content": [
                "Version"
              ],
              "font": "DejaVuSans",
              "font_size": 10.0,
              "padding": {
                "left": 6.0,
                "right": 6.0,
                "top": 4.0,
                "bottom": 4.0
              }
            },
            {
              "content": [
                "1.0"
              ],
              "font": "DejaVuSans",
              "font_size": 10.0,
              "padding": {
                "left": 6.0,
                "right": 6.0,
                "top": 4.0,
                "bottom": 4.0
              }
            }
          ]
        }
      ]
    },
    {
      "type": "rect",
      "rect": {
        "llx": 210.0,
        "lly": 550.0,
        "urx": 525.0,
        "ury": 570.0
      },
      "stroke": {
        "width": 1.0,
        "color": [
          0.8,
          0.0,
          0.0
        ]
      }
    },
    {
      "type": "link",
      "rect": {
        "llx": 70.0,
        "lly": 637.769921875,
        "urx": 387.53125,
        "ury": 651.738671875
      },
      "to": {
        "uri": "https://example.org/hqf-pdf/terms"
      }
    },
    {
      "type": "link",
      "rect": {
        "llx": 210.0,
        "lly": 550.0,
        "urx": 525.0,
        "ury": 570.0
      },
      "to": {
        "uri": "https://example.org/hqf-pdf/licence"
      }
    }
  ]
}