Guide

Write handwriting

One request writes handwriting onto a set of lines. Loop on what's left to fill as many pages as you like.

POST/v1/handwriting

Request

curl https://www.deepscribble.com/api/v1/handwriting \
  -H "Authorization: Bearer $DEEPSCRIBBLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Dear Sam,\nThank you for the flowers. They made my whole week!",
    "regions": [
      {
        "x": 40,
        "y": 84,
        "width": 520,
        "height": 44
      },
      {
        "x": 40,
        "y": 148,
        "width": 520,
        "height": 44
      },
      {
        "x": 40,
        "y": 212,
        "width": 520,
        "height": 44
      }
    ]
  }'

Response

{
  "id": "req_67f48ae3e0b9453ab634e486f6ca485e",
  "object": "handwriting",
  "created": 1796481762,
  "style": "9d914b41-0358-49eb-9e2c-bfdb06163b60",
  "width": 560,
  "height": 214,
  "lines": [
    {
      "region": 0,
      "text": "Dear Sam,",
      "bbox": [47.663, 56.069, 112.795, 32.584]
    },
    {
      "region": 1,
      "text": "Thank you for the flowers. They made my",
      "bbox": [47.494, 116.854, 463.002, 48.963]
    },
    {
      "region": 2,
      "text": "whole week!",
      "bbox": [47.494, 184.54, 124.119, 28.817]
    }
  ],
  "regions_used": 3,
  "remaining_text": "",
  "done": true,
  "substitutions": [],
  "usage": { "characters": 59, "cost": "0.118", "currency": "INR" },
  "balance": { "amount": "1.882", "currency": "INR" },
  "svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 560 214\" width=\"560\" height=\"214\">…</svg>"
}

How text fills your regions

  • A region is one line of writing. x and y mark where the line starts, width runs along it, and height is the room for letters above it. Descenders hang below, just like on ruled paper.
  • Regions fill in the order you send them. A long line carries on into the next region, and words always stay whole.
  • A new line in your text starts the next region. A blank line leaves a region empty, which is handy for paragraph gaps.
  • Use any unit; the response comes back in the same one.
How a region is built: x and y mark where the line starts, width runs along it, height is the room above it, and rotation turns it around its start.0, 0xybaselineheightwidthx, yrotationdegrees, clockwise around x, yUnits are yours: px, pt or mm.The response uses the same ones.Letters sit on the baseline;descenders hang below it.

What each setting changes

x, yregion
Where the line starts. Moves the writing.
widthregion
How far the line runs, so how many characters fit before the text carries on to the next region.
heightregion
Letter size. Taller regions write bigger, with a matching pen.
rotationregion
Tilts the line, turning around its start.
ink.thicknessink
Pen weight, relative to the region's height.
stylewriting
The hand: shape, slant and how joined-up the letters are.
legibilitywriting
How neat the letters are, from loose to tidy.

Request

textstring · required
Up to 20,000 characters. Whatever doesn't fit comes back in remaining_text.
regionsarray · required
1–50 lines, each { x, y, width, height, rotation? } with x, y at the start of the line. rotation is in degrees, clockwise around that start.
stylestring
A style id from GET /v1/styles. Defaults to the first style in the catalog.
ink.colorstring
Hex colour. Default #2563eb.
ink.thicknessnumber
Pen weight from 0.4 to 3. Default 1.2. It scales with each region's height.
ink.finishstring
ink (default), glitter, foil or holo.
legibilitynumber
0 to 1. Higher is neater. Default 0.8.
canvasobject
{ width, height }for the SVG's viewBox, usually your page size. Defaults to the area your regions cover.
formatstring
svg (default) returns one SVG document. paths returns an outline per line for your own renderer, PDF library or plotter.
dry_runboolean
Plan the fit and price without writing anything. Free.

Response

svgstring
The handwriting in your coordinates, ready to place over your page.
linesarray
What went onto each region: its index, the text, and a bbox of [x, y, width, height]. With format: "paths", each line also has a path to fill with the top-level fill colour.
regions_usednumber
How many of your regions this request filled, blank ones included.
remaining_textstring
Text still to write. Empty when done is true.
substitutionsarray
Characters that were swapped or left out, such as { "from": "é", "to": "e" }.
usageobject
Characters billed for this request and what they cost.
balanceobject
Your balance after this request.

Filling whole pages

One request writes up to 800 characters (400 with glitter). Keep going with the regions you haven't used yet plus remaining_text, and start a fresh set of regions when a page is full. Every SVG shares your page's coordinates, so the pieces of one page layer cleanly.

async function write(body) {
  const res = await fetch("https://www.deepscribble.com/api/v1/handwriting", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.DEEPSCRIBBLE_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(body),
  });
  if (!res.ok) throw new Error((await res.json()).error.message);
  return res.json();
}

// ruledLines() returns the regions of one fresh page.
let text = letter;
let page = 0;
let regions = ruledLines();
const layers = []; // [page, svg]

while (text) {
  const res = await write({ text, regions, style: STYLE_ID });
  layers.push([page, res.svg]);
  text = res.remaining_text;
  regions = regions.slice(res.regions_used);
  if (regions.length === 0) {
    page += 1;
    regions = ruledLines();
  }
}

Check the fit first

Add "dry_run": trueto see which text lands in which region, what's left over, and the price, before you spend anything.

Request

curl https://www.deepscribble.com/api/v1/handwriting \
  -H "Authorization: Bearer $DEEPSCRIBBLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Dear Sam,\nThank you for the flowers. They made my whole week!",
    "regions": [
      {
        "x": 40,
        "y": 84,
        "width": 520,
        "height": 44
      },
      {
        "x": 40,
        "y": 148,
        "width": 520,
        "height": 44
      },
      {
        "x": 40,
        "y": 212,
        "width": 520,
        "height": 44
      }
    ],
    "dry_run": true
  }'

Response

{
  "id": "req_5c0e9d2f8a1b4c6e9f7a3b2d1c0e8f6a",
  "object": "handwriting",
  "created": 1796481700,
  "style": "9d914b41-0358-49eb-9e2c-bfdb06163b60",
  "dry_run": true,
  "lines": [
    { "region": 0, "text": "Dear Sam," },
    { "region": 1, "text": "Thank you for the flowers. They made my" },
    { "region": 2, "text": "whole week!" }
  ],
  "regions_used": 3,
  "remaining_text": "",
  "done": true,
  "substitutions": [],
  "usage": { "characters": 0, "cost": "0.000", "currency": "INR" },
  "balance": { "amount": "2.000", "currency": "INR" },
  "estimate": { "characters": 59, "cost": "0.118", "currency": "INR" }
}

Characters

Handwriting covers English letters, digits and common punctuation. Other characters are swapped for a close match, so é becomes e and & becomes and, and every swap is listed in substitutions. Each region writes up to 100 characters.

Every response carries its request id (id, or request_id on errors), also sent as the x-request-idheader. It's the fastest way for us to help if something looks off.
NextStyles