write_rich_text.json

The JSON file of the “Changing style in the middle of a paragraph” example. A paragraph whose style changes inside it: size, underline, colour.

JSON 112 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.

What this example is for

Most text in a real document is not one style from end to end. A sentence has a bold term, a total is underlined, a footnote marker is smaller than the words around it. The usual workaround is to cut the sentence into pieces and place each one after the last — which holds until the text is translated and the pieces no longer add up to the same width.

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
{
  "items": [
    {
      "type": "text",
      "rect": {
        "llx": 56.0,
        "lly": 784.0,
        "urx": 539.276,
        "ury": 800.8
      },
      "content": [
        "Rich text: styles, sizes, underlining, colour"
      ],
      "font": "DejaVuSans",
      "font_size": 14.0
    },
    {
      "type": "text",
      "rect": {
        "llx": 56.0,
        "lly": 720.4,
        "urx": 476.0,
        "ury": 760.0
      },
      "content": [
        "The amount due is ",
        {
          "text": "1 240.00 EUR",
          "underline": true
        },
        ", payable within thirty days. The balance carries interest at the statutory rate from the day it falls due, and no reminder has to be sent for it to do so."
      ],
      "font": "DejaVuSans",
      "font_size": 11.0,
      "align": "justify"
    },
    {
      "type": "text",
      "rect": {
        "llx": 56.0,
        "lly": 660.8,
        "urx": 476.0,
        "ury": 694.4
      },
      "content": [
        "A line is as tall as ",
        {
          "text": "the largest",
          "font_size": 17.0
        },
        " of the styles standing on it, and no taller."
      ],
      "font": "DejaVuSans",
      "font_size": 11.0
    },
    {
      "type": "text",
      "rect": {
        "llx": 56.0,
        "lly": 621.6,
        "urx": 476.0,
        "ury": 634.8
      },
      "content": [
        "A run can carry its own ",
        {
          "text": "colour",
          "color": [0.0, 0.35, 0.7]
        },
        ", set apart from the black around it."
      ],
      "font": "DejaVuSans",
      "font_size": 11.0
    },
    {
      "type": "text",
      "rect": {
        "llx": 56.0,
        "lly": 569.2,
        "urx": 476.0,
        "ury": 595.6
      },
      "content": [
        "A word may change style in the middle: under",
        {
          "text": "lined",
          "underline": true
        },
        " is still one word, and is never broken at the join."
      ],
      "font": "DejaVuSans",
      "font_size": 11.0
    },
    {
      "type": "text",
      "rect": {
        "llx": 56.0,
        "lly": 533.6,
        "urx": 476.0,
        "ury": 543.2
      },
      "content": [
        "The small print sits in small type, ",
        "flush right",
        ", below the body of the text."
      ],
      "font": "DejaVuSans",
      "font_size": 8.0,
      "align": "right"
    }
  ]
}