Shipping label
Build a shipping label and stamp text onto the finished file. You learn taking a JPEG and stamping text or a watermark onto an existing PDF.
このレシピで身につくこと
エディタで作る
- Split sender and recipient into two rectangles. Rounding the corners makes the two blocks easy to tell apart in print.
- Add a tracking QR with the tracking address as its value. This one is scanned by phone, so QR is the right kind.
- Shipping labels get folded and wet. Do not use small type, and keep the important lines bold.
スキーマと API で作る
- Set format to "jpeg" for a JPEG. You can add quality from 1 to 100.
- quality applies to JPEG only. Sent with PNG it is rejected rather than ignored — a silently ignored option looks like a fault on our side.
- To stamp an existing PDF, upload it with POST /v1/files and call POST /v1/pdf/stamp. text is required; pages, x, y, size, opacity, rotate and color are optional.
- A watermark and added text are the same engine with different options. Pages count from 1, and coordinates are in pt from the bottom-left of the page.
- Stamped text must be Latin-1. Non-Latin characters are rejected — the standard fonts cannot draw them, and refusing beats silently printing rubbish.
作ったあとに
Stamp the finished file
POST /v1/pdf/stamp
{
"file": "file_01J…",
"text": "REPRINT",
"pages": [
1
],
"size": 48,
"opacity": 0.15,
"rotate": 30,
"color": "#d92d20"
}出来上がったドキュメント
下の JSON は、2 つの道筋が生むドキュメントそのものです。テストがこれを検証し、警告なしでレンダリングされることも確認しているので、そのまま貼り付けてお使いいただけます。
{
"v": 1,
"unit": "px",
"page": {
"size": "a5",
"orientation": "portrait",
"margin": {
"t": 14,
"r": 14,
"b": 14,
"l": 14
},
"header": "",
"footer": ""
},
"fonts": [],
"styles": [
{
"id": "s_h",
"fontFamily": "Liberation Sans",
"fontSize": 11,
"fontWeight": 400,
"italic": false,
"color": "#666666",
"bg": "transparent",
"align": "left",
"valign": "top",
"lineHeight": 1.5,
"border": "none",
"radius": 0,
"opacity": 1
},
{
"id": "s_b",
"fontFamily": "Liberation Sans",
"fontSize": 16,
"fontWeight": 700,
"italic": false,
"color": "#111111",
"bg": "transparent",
"align": "left",
"valign": "top",
"lineHeight": 1.5,
"border": "none",
"radius": 0,
"opacity": 1
},
{
"id": "s_l",
"fontFamily": "Liberation Sans",
"fontSize": 12,
"fontWeight": 400,
"italic": false,
"color": "#222222",
"bg": "transparent",
"align": "left",
"valign": "top",
"lineHeight": 1.5,
"border": "none",
"radius": 0,
"opacity": 1
},
{
"id": "s_box",
"fontFamily": "Liberation Sans",
"fontSize": 12,
"fontWeight": 400,
"italic": false,
"color": "#111111",
"bg": "transparent",
"align": "left",
"valign": "top",
"lineHeight": 1.5,
"border": "none",
"radius": 10,
"opacity": 1
}
],
"nodes": [
{
"id": "n_from",
"parent": "",
"order": 0,
"type": "rect",
"x": 0,
"y": 0,
"w": 391,
"h": 96,
"show": "",
"styleId": "s_box",
"props": {
"text": "",
"src": "",
"fit": "",
"thickness": 1,
"stroke": "#dfe3e8",
"fill": "#fafbfc",
"repeat": "",
"as": "",
"break": "",
"keep": "",
"padding": 0,
"padY": 0,
"padX": 0,
"align": "",
"valign": "",
"wrap": "",
"bind": "",
"headerHeight": 0,
"rowHeight": 0,
"max": 0,
"columns": [],
"rows": 0,
"cells": [],
"chartKind": "",
"codeKind": "",
"ecc": "",
"fieldKind": "",
"fieldName": "",
"options": [],
"required": false,
"readonly": false,
"html": ""
},
"name": "Sender block"
},
{
"id": "n_from_h",
"parent": "n_from",
"order": 1,
"type": "label",
"x": 12,
"y": 10,
"w": 360,
"h": 14,
"show": "",
"styleId": "s_h",
"props": {
"text": "From",
"src": "",
"fit": "",
"thickness": 0,
"stroke": "",
"fill": "",
"repeat": "",
"as": "",
"break": "",
"keep": "",
"padding": 0,
"padY": 0,
"padX": 0,
"align": "",
"valign": "",
"wrap": "",
"bind": "",
"headerHeight": 0,
"rowHeight": 0,
"max": 0,
"columns": [],
"rows": 0,
"cells": [],
"chartKind": "",
"codeKind": "",
"ecc": "",
"fieldKind": "",
"fieldName": "",
"options": [],
"required": false,
"readonly": false,
"html": ""
},
"name": "From caption"
},
{
"id": "n_from_n",
"parent": "n_from",
"order": 2,
"type": "label",
"x": 12,
"y": 28,
"w": 360,
"h": 20,
"show": "",
"styleId": "s_b",
"props": {
"text": "{{ data.from.name }}",
"src": "",
"fit": "",
"thickness": 0,
"stroke": "",
"fill": "",
"repeat": "",
"as": "",
"break": "",
"keep": "",
"padding": 0,
"padY": 0,
"padX": 0,
"align": "",
"valign": "",
"wrap": "",
"bind": "",
"headerHeight": 0,
"rowHeight": 0,
"max": 0,
"columns": [],
"rows": 0,
"cells": [],
"chartKind": "",
"codeKind": "",
"ecc": "",
"fieldKind": "",
"fieldName": "",
"options": [],
"required": false,
"readonly": false,
"html": ""
},
"name": "Sender"
},
{
"id": "n_from_a",
"parent": "n_from",
"order": 3,
"type": "label",
"x": 12,
"y": 50,
"w": 360,
"h": 0,
"show": "",
"styleId": "s_l",
"props": {
"text": "{{ data.from.address }}",
"src": "",
"fit": "",
"thickness": 0,
"stroke": "",
"fill": "",
"repeat": "",
"as": "",
"break": "",
"keep": "",
"padding": 0,
"padY": 0,
"padX": 0,
"align": "",
"valign": "",
"wrap": "",
"bind": "",
"headerHeight": 0,
"rowHeight": 0,
"max": 0,
"columns": [],
"rows": 0,
"cells": [],
"chartKind": "",
"codeKind": "",
"ecc": "",
"fieldKind": "",
"fieldName": "",
"options": [],
"required": false,
"readonly": false,
"html": ""
},
"name": "Sender address"
},
{
"id": "n_to",
"parent": "",
"order": 4,
"type": "rect",
"x": 0,
"y": 112,
"w": 391,
"h": 120,
"show": "",
"styleId": "s_box",
"props": {
"text": "",
"src": "",
"fit": "",
"thickness": 2,
"stroke": "#111111",
"fill": "",
"repeat": "",
"as": "",
"break": "",
"keep": "",
"padding": 0,
"padY": 0,
"padX": 0,
"align": "",
"valign": "",
"wrap": "",
"bind": "",
"headerHeight": 0,
"rowHeight": 0,
"max": 0,
"columns": [],
"rows": 0,
"cells": [],
"chartKind": "",
"codeKind": "",
"ecc": "",
"fieldKind": "",
"fieldName": "",
"options": [],
"required": false,
"readonly": false,
"html": ""
},
"name": "Recipient block"
},
{
"id": "n_to_h",
"parent": "n_to",
"order": 5,
"type": "label",
"x": 12,
"y": 10,
"w": 360,
"h": 14,
"show": "",
"styleId": "s_h",
"props": {
"text": "To",
"src": "",
"fit": "",
"thickness": 0,
"stroke": "",
"fill": "",
"repeat": "",
"as": "",
"break": "",
"keep": "",
"padding": 0,
"padY": 0,
"padX": 0,
"align": "",
"valign": "",
"wrap": "",
"bind": "",
"headerHeight": 0,
"rowHeight": 0,
"max": 0,
"columns": [],
"rows": 0,
"cells": [],
"chartKind": "",
"codeKind": "",
"ecc": "",
"fieldKind": "",
"fieldName": "",
"options": [],
"required": false,
"readonly": false,
"html": ""
},
"name": "To caption"
},
{
"id": "n_to_n",
"parent": "n_to",
"order": 6,
"type": "label",
"x": 12,
"y": 28,
"w": 360,
"h": 26,
"show": "",
"styleId": "s_b",
"props": {
"text": "{{ data.to.name }}",
"src": "",
"fit": "",
"thickness": 0,
"stroke": "",
"fill": "",
"repeat": "",
"as": "",
"break": "",
"keep": "",
"padding": 0,
"padY": 0,
"padX": 0,
"align": "",
"valign": "",
"wrap": "",
"bind": "",
"headerHeight": 0,
"rowHeight": 0,
"max": 0,
"columns": [],
"rows": 0,
"cells": [],
"chartKind": "",
"codeKind": "",
"ecc": "",
"fieldKind": "",
"fieldName": "",
"options": [],
"required": false,
"readonly": false,
"html": ""
},
"name": "Recipient"
},
{
"id": "n_to_a",
"parent": "n_to",
"order": 7,
"type": "label",
"x": 12,
"y": 56,
"w": 360,
"h": 0,
"show": "",
"styleId": "s_l",
"props": {
"text": "{{ data.to.address }}",
"src": "",
"fit": "",
"thickness": 0,
"stroke": "",
"fill": "",
"repeat": "",
"as": "",
"break": "",
"keep": "",
"padding": 0,
"padY": 0,
"padX": 0,
"align": "",
"valign": "",
"wrap": "",
"bind": "",
"headerHeight": 0,
"rowHeight": 0,
"max": 0,
"columns": [],
"rows": 0,
"cells": [],
"chartKind": "",
"codeKind": "",
"ecc": "",
"fieldKind": "",
"fieldName": "",
"options": [],
"required": false,
"readonly": false,
"html": ""
},
"name": "Recipient address"
},
{
"id": "n_qr",
"parent": "",
"order": 8,
"type": "code",
"x": 0,
"y": 248,
"w": 120,
"h": 120,
"show": "",
"styleId": "s_l",
"props": {
"text": "https://track.example.com/{{ data.tracking }}",
"src": "",
"fit": "",
"thickness": 0,
"stroke": "",
"fill": "",
"repeat": "",
"as": "",
"break": "",
"keep": "",
"padding": 0,
"padY": 0,
"padX": 0,
"align": "",
"valign": "",
"wrap": "",
"bind": "",
"headerHeight": 0,
"rowHeight": 0,
"max": 0,
"columns": [],
"rows": 0,
"cells": [],
"chartKind": "",
"codeKind": "qr",
"ecc": "M",
"fieldKind": "",
"fieldName": "",
"options": [],
"required": false,
"readonly": false,
"html": ""
},
"name": "Tracking QR"
},
{
"id": "n_track",
"parent": "",
"order": 9,
"type": "label",
"x": 136,
"y": 268,
"w": 255,
"h": 24,
"show": "",
"styleId": "s_b",
"props": {
"text": "{{ data.tracking }}",
"src": "",
"fit": "",
"thickness": 0,
"stroke": "",
"fill": "",
"repeat": "",
"as": "",
"break": "",
"keep": "",
"padding": 0,
"padY": 0,
"padX": 0,
"align": "",
"valign": "",
"wrap": "",
"bind": "",
"headerHeight": 0,
"rowHeight": 0,
"max": 0,
"columns": [],
"rows": 0,
"cells": [],
"chartKind": "",
"codeKind": "",
"ecc": "",
"fieldKind": "",
"fieldName": "",
"options": [],
"required": false,
"readonly": false,
"html": ""
},
"name": "Tracking number"
}
]
}リクエストの本文です。上のドキュメントを template に、下のデータを data に入れてください。
{
"template": "(the document above)",
"data": {
"from": {
"name": "brewmypdf",
"address": "118 Seongsui-ro, Seongdong-gu, Seoul"
},
"to": {
"name": "Do-hyun Kim",
"address": "145 Gwanggyo-ro, Yeongtong-gu, Suwon — Apt 302-1201"
},
"tracking": "BM1234567890"
},
"format": "jpeg",
"quality": 92
}