@formancy/report-render-pdf 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +8 -0
- package/README.md +907 -37
- package/dist/bill-fonts-B61mmaVd.mjs +16 -0
- package/dist/bill-fonts-B61mmaVd.mjs.map +1 -0
- package/dist/browser.d.mts +8 -3
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.mjs +90 -20
- package/dist/browser.mjs.map +1 -1
- package/dist/chart-draw-CUcWXjN9.mjs +1056 -0
- package/dist/chart-draw-CUcWXjN9.mjs.map +1 -0
- package/dist/index.d.mts +1 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +59 -23
- package/dist/index.mjs.map +1 -1
- package/dist/{options-wLxIWA87.d.mts → options-B7fd-ZYd.d.mts} +13 -3
- package/dist/options-B7fd-ZYd.d.mts.map +1 -0
- package/dist/render-D4q7IZ7I.mjs +5139 -0
- package/dist/render-D4q7IZ7I.mjs.map +1 -0
- package/fonts/AUTHORS-LiberationSans.txt +16 -0
- package/fonts/LICENSE-LiberationSans.txt +102 -0
- package/fonts/LiberationSans-Bold.ttf +0 -0
- package/fonts/LiberationSans-Regular.ttf +0 -0
- package/package.json +12 -7
- package/dist/options-wLxIWA87.d.mts.map +0 -1
- package/dist/render-Bs7DXIYJ.mjs +0 -1943
- package/dist/render-Bs7DXIYJ.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ import { renderPdf, RenderRefusal } from '@formancy/report-render-pdf'
|
|
|
18
18
|
|
|
19
19
|
try {
|
|
20
20
|
const pdf: Uint8Array = await renderPdf(document, { maxPages: 200, signal })
|
|
21
|
-
// the whole report, every page of it
|
|
21
|
+
// the whole report, every page of it; with pdfa: '2b', a PDF/A-2b of it
|
|
22
22
|
} catch (error) {
|
|
23
23
|
if (!(error instanceof RenderRefusal)) throw error // the engine failing, not the report
|
|
24
24
|
// error.code says what stopped it; error.subject names the asset, table
|
|
@@ -30,29 +30,63 @@ try {
|
|
|
30
30
|
`renderPdf` resolves to the PDF's bytes, or rejects with a `RenderRefusal`.
|
|
31
31
|
A refusal is decided before the PDF is written: a refused report has no
|
|
32
32
|
PDF at all. Anything else it rejects with is a fault, and a `maxPages` that
|
|
33
|
-
is not a whole number of pages, at least 1,
|
|
33
|
+
is not a whole number of pages, at least 1, or a `pdfa` other than `'2b'`,
|
|
34
|
+
is the caller's: a `RangeError`.
|
|
34
35
|
|
|
35
36
|
The same document renders to the same bytes: the creation date is the
|
|
36
37
|
document's own (`info.creationDate`), and nothing else in the file varies.
|
|
38
|
+
That includes where its images stand in the file. PDFKit decodes a PNG
|
|
39
|
+
with an alpha channel, a palette's transparency or interlacing before it
|
|
40
|
+
embeds it, and numbers its soft mask and writes it when the decode calls
|
|
41
|
+
back, in whatever order the decodes finish; the renderer has those images
|
|
42
|
+
written in the order pdfmake opened them, which `src/image-order.test.ts`
|
|
43
|
+
holds in both entries
|
|
44
|
+
([0035](../../docs/decisions/0035-the-renderer-writes-the-images-pdfkit-decodes-in-the-order-pdfmake-opened-them.md)).
|
|
45
|
+
The bytes are one entry's: the browser build deflates with a zlib of its
|
|
46
|
+
own, and `src/browser.test.ts` holds an e-invoice from either entry to the
|
|
47
|
+
same objects, each stream inflated, not to the same file.
|
|
37
48
|
|
|
38
49
|
## Node and the browser
|
|
39
50
|
|
|
40
51
|
| Entry | pdfmake | Fonts |
|
|
41
52
|
|---|---|---|
|
|
42
|
-
| `@formancy/report-render-pdf` | the Node build | the four Roboto files in pdfmake's package, read from disk |
|
|
43
|
-
| `@formancy/report-render-pdf/browser` | the browser build, `pdfmake/build/pdfmake.js` | the same Roboto, from pdfmake's `build/vfs_fonts.js
|
|
53
|
+
| `@formancy/report-render-pdf` | the Node build | the four Roboto files in pdfmake's package, and for a QR-bill's slip and an EPC QR code's caption the two Liberation Sans files in this package's `fonts`, read from disk; for a PDF/A, an e-invoice's or a PDF/A-2b, PDFKit reads its ICC profile from its own package (below) |
|
|
54
|
+
| `@formancy/report-render-pdf/browser` | the browser build, `pdfmake/build/pdfmake.js` | the same Roboto, from pdfmake's `build/vfs_fonts.js`, and the same Liberation Sans from a chunk of the build's own, imported the first time a document has a bill or a captioned EPC QR code |
|
|
44
55
|
|
|
45
56
|
The two entries share everything but the build of pdfmake and where the
|
|
46
57
|
fonts come from: the checks, the measuring passes and the document
|
|
47
58
|
definitions are one module both import. The browser entry touches no file
|
|
48
|
-
system and imports no `node:` module.
|
|
59
|
+
system and imports no `node:` module. Liberation Sans reaches it through a
|
|
60
|
+
dynamic import alone, so an app's bundler puts it in a chunk that a host
|
|
61
|
+
which never prints a bill or a captioned EPC QR code never loads, which a
|
|
62
|
+
test holds. An import that fails is not kept: the document it failed for
|
|
63
|
+
rejects with its error, and the next bill or caption imports the chunk
|
|
64
|
+
again; once it has loaded, nothing imports it again. The Node entry keeps
|
|
65
|
+
its reads of the font files the same way, so a file it could not open just
|
|
66
|
+
then fails the render that asked for it and no render after.
|
|
67
|
+
Whether a browser fetches a chunk again after a failure, or a chunk a
|
|
68
|
+
deploy removed is still there, is not the renderer's to decide: a page
|
|
69
|
+
reload is.
|
|
70
|
+
|
|
71
|
+
A chart is laid out by Apache ECharts, which only `src/chart-draw.ts`
|
|
72
|
+
imports, and both entries import that module, through the same `loadOnce`,
|
|
73
|
+
the first time a document holds a chart with something to draw. In a
|
|
74
|
+
browser it is a chunk of its own, with ECharts and zrender in it, which a
|
|
75
|
+
page that draws no chart, or only empty ones, never loads, and
|
|
76
|
+
`src/browser.test.ts` counts the loads. ECharts' components are registered
|
|
77
|
+
at the first chart, never at import, and the package is
|
|
78
|
+
`sideEffects: false`. A chart's words are measured, in either entry, by
|
|
79
|
+
the entry's own pdfmake, in the faces it embeds (below).
|
|
49
80
|
|
|
50
81
|
What the tests show about the browser entry, run in Node: for every fixture
|
|
51
82
|
in the corpus it hands pdfmake the definitions the Node entry does, its PDFs
|
|
52
83
|
pass the corpus's checks, it places every run and image where the Node entry
|
|
53
84
|
does, and it reaches no Node module. What they do not show is the browser
|
|
54
|
-
build in a browser. That is the Studio's browser gate's to check
|
|
55
|
-
|
|
85
|
+
build in a browser. That is the Studio's browser gate's to check:
|
|
86
|
+
`apps/studio/scripts/browser-test.mjs`, in CI's `browser` job, prints
|
|
87
|
+
every starter through this entry in Chromium and reads its text back, and
|
|
88
|
+
no other browser runs it
|
|
89
|
+
([0013](../../docs/decisions/0013-the-studio-is-the-same-room-and-its-pictures-are-taken-by-a-script.md)).
|
|
56
90
|
|
|
57
91
|
pdfmake is one configuration per process, or per page in a browser: fonts
|
|
58
92
|
and access policies are global to it. The renderer sets its own again
|
|
@@ -65,13 +99,30 @@ after a report, the renderer's configuration is in place.
|
|
|
65
99
|
Every block of the resolved document:
|
|
66
100
|
|
|
67
101
|
- **Paragraphs**, in their size, weight, slant, colour and alignment, and
|
|
68
|
-
a run in bold inside a paragraph that is not
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
102
|
+
a run in bold inside a paragraph that is not, or set below or above the
|
|
103
|
+
line (below).
|
|
104
|
+
- **Tables**, their header row repeated on every page they span -- a
|
|
105
|
+
table the runtime resolves with no header row, every title it shows
|
|
106
|
+
printing nothing, prints none and no band where one would stand, on any
|
|
107
|
+
page
|
|
108
|
+
([0078](../../docs/decisions/0078-a-table-whose-every-column-title-prints-nothing-has-no-header-row.md))
|
|
109
|
+
-- each row in its kind's style or its own, each cell in its own when it
|
|
110
|
+
has one, each column aligned as it says unless a cell says otherwise. A group header
|
|
72
111
|
`across` the table is one cell over every column. A group header is never
|
|
73
112
|
the last row on a page, and a row that fits on a page is never split. A
|
|
74
|
-
group
|
|
113
|
+
group header row that keeps more of its group's first rows
|
|
114
|
+
(`keepWithRows`) stands on the page of as many of them as fit there under
|
|
115
|
+
the repeated column header, and of its first row where no more do: a
|
|
116
|
+
group no longer than its count stands whole, with its footers, where it
|
|
117
|
+
fits, held by the last of them that prints though a footer row after it
|
|
118
|
+
prints nothing; a block short of its group ends on the last of those
|
|
119
|
+
rows that prints, since a rule finds a row on its page by its text; a
|
|
120
|
+
header that prints nothing keeps no more than its first row; and a
|
|
121
|
+
count on a row that is
|
|
122
|
+
no group header, outside 2 to `MAX_KEEP_WITH_ROWS`, or past the detail
|
|
123
|
+
rows under the header is refused as `unsupported`, naming the table
|
|
124
|
+
([0059](../../docs/decisions/0059-a-group-header-is-kept-on-its-page-with-as-many-of-its-groups-first-rows-as-the-report-states-or-as-fit.md)).
|
|
125
|
+
A group's footers and the totals under the last row stand on the page of
|
|
75
126
|
the row before them, and with its group header when that row is its
|
|
76
127
|
group's first: a subtotal or a total never stands alone at the top of a
|
|
77
128
|
page. Every column is as wide as it says, a fill column its share of
|
|
@@ -79,7 +130,29 @@ Every block of the resolved document:
|
|
|
79
130
|
- **Images**, in a box the layout reserves whole: `contain` draws all of
|
|
80
131
|
the image at its proportions, as large as the box allows, centred in it;
|
|
81
132
|
`cover` fills the box, centred, and is clipped to it. A JPEG is fitted by
|
|
82
|
-
the size it is shown at, after its Exif orientation.
|
|
133
|
+
the size it is shown at, after its Exif orientation. An SVG is drawn as
|
|
134
|
+
vectors (below), fitted by its viewBox.
|
|
135
|
+
- **QR codes** (ISO/IEC 18004), their symbol the runtime's, which
|
|
136
|
+
encodes it with [uqr](https://github.com/unjs/uqr)
|
|
137
|
+
in the smallest version that holds their text at the level asked for,
|
|
138
|
+
never a higher level, and drawn in vectors as a square exactly their size:
|
|
139
|
+
white, with the quiet zone of four modules inside it, and the dark
|
|
140
|
+
modules one black path over it, filled once, so that no viewer draws a
|
|
141
|
+
light line where two rows meet inside a pixel. The square is an SVG,
|
|
142
|
+
which pdfmake places as it places an image: a path in a pdfmake 0.3.11
|
|
143
|
+
canvas is never moved to where the canvas stands. Its text is never
|
|
144
|
+
printed, so it is not held to the font: umlauts, the euro sign and emoji
|
|
145
|
+
are encoded as UTF-8, and text of digits or capitals alone in the denser
|
|
146
|
+
modes for them. Each code is encoded once, when the document is checked,
|
|
147
|
+
and that symbol is the one every pass and every page draws. A heading
|
|
148
|
+
kept with the next block is kept with a code as with an image. What a
|
|
149
|
+
large code adds to a render's time and to the PDF, and what the one fill
|
|
150
|
+
costs against a rectangle for each run, is measured in
|
|
151
|
+
[0020](../../docs/decisions/0020-a-qr-code-is-drawn-from-its-own-matrix-and-refused-where-it-may-not-scan.md).
|
|
152
|
+
- **EPC QR codes** (EPC069-12 version 3.1), the code a SEPA credit
|
|
153
|
+
transfer is initiated from: the runtime's payload encoded as a QR code's
|
|
154
|
+
text is, at level M and in version 13 at most, and drawn as a QR code
|
|
155
|
+
is, or in Austria's frame with "Zahlen mit Code" beside it (below).
|
|
83
156
|
- **Rules**, at their thickness and colour, across the width they stand in,
|
|
84
157
|
with 3 pt above and below.
|
|
85
158
|
- **Rectangles**, filled, outlined or both, their outline drawn inside the
|
|
@@ -91,24 +164,592 @@ Every block of the resolved document:
|
|
|
91
164
|
body, tables and page breaks included; without one, its blocks and nothing
|
|
92
165
|
more.
|
|
93
166
|
- **Keep-together blocks**, moved whole to the next page when they do not
|
|
94
|
-
fit, and paragraphs **kept with the next** block.
|
|
167
|
+
fit, and paragraphs **kept with the next** block. A table is kept with by
|
|
168
|
+
its first row under the column header, and by its header only where no
|
|
169
|
+
row prints, or inside a keep-together block, which moves whole: pdfmake
|
|
170
|
+
repeats the header on every page the table continues on and writes that
|
|
171
|
+
page into it, so a heading over a table that runs past its page stays on
|
|
172
|
+
its page with the table's first rows. Where a table whose rows print
|
|
173
|
+
nothing runs past its page, its heading still moves with it
|
|
174
|
+
([0011](../../docs/decisions/0011-report-render-pdf-draws-the-document-and-refuses-what-it-cannot.md)).
|
|
95
175
|
- **The page header and footer**, on every page, with the page number and
|
|
96
176
|
the page count. The body is laid out between them, after both are
|
|
97
177
|
measured.
|
|
178
|
+
- **Page 1's own header**, where the document has one ([0060](../../docs/decisions/0060-a-reports-first-page-may-print-a-header-of-its-own-or-none-in-place-of-the-page-header.md)), on
|
|
179
|
+
page 1 in the page header's place; the page header then prints from page
|
|
180
|
+
2 on. It is drawn in page 1's background, at the margin the page header
|
|
181
|
+
stands at, measured in a pass of its own, and page 1's body starts below
|
|
182
|
+
it and the gap, or at the top margin where it is empty, which is page 1
|
|
183
|
+
with no header. It holds no page field: page 1's number and count print in
|
|
184
|
+
the page footer, which page 1 prints as every page does.
|
|
185
|
+
- **A QR-bill's payment part**, the receipt and the payment part with its
|
|
186
|
+
Swiss QR Code, across the foot of the last page in place of its page
|
|
187
|
+
footer (below).
|
|
188
|
+
- **Charts**, a bar, a line or a pie chart in its box, laid out by Apache
|
|
189
|
+
ECharts, its marks drawn as vectors and its words as text in the
|
|
190
|
+
report's faces (below).
|
|
98
191
|
|
|
99
192
|
## What it refuses
|
|
100
193
|
|
|
101
194
|
| Code | When |
|
|
102
195
|
|---|---|
|
|
103
|
-
| `too-many-pages` | The report needs more pages than `maxPages
|
|
104
|
-
| `content-too-large` | Something no page can hold: a keep-together block, an image, a rectangle, a rule, a frame's border and padding, or a line of text taller than the body where it stands; anything wider than where it stands; a word in a table cell wider than its column, or a word in a paragraph longer than 16 lines of it; images holding more than 268,443,648 bytes of image data together; page regions that leave no body. |
|
|
105
|
-
| `invalid-asset` | An image's bytes are not the PNG or
|
|
196
|
+
| `too-many-pages` | The report needs more pages than `maxPages`, a QR-bill's page included. pdfmake's own limit would return the first pages as though they were all of it. A body whose least height already needs more, the room a bill's slip keeps included, is refused before pdfmake measures it. |
|
|
197
|
+
| `content-too-large` | Something no page can hold: a keep-together block, an image, a QR code, a rectangle, a rule, a frame's border and padding, or a line of text taller than the body where it stands; a line of a table's row that a page does not hold under the table's repeated header with a point to spare, which pdfmake would drop, naming the table, the row and its kind and both heights (0011); anything wider than where it stands; a word in a table cell wider than its column, or a word in a paragraph longer than 16 lines of it; images holding more than 268,443,648 bytes of image data together; SVG images past what a render may draw or a page may cost a reader (below); page regions that leave no body, and page 1's own header that leaves page 1 none or is taller than the printable area, naming `firstPageHeader` (0060); where page 1 has a header of its own, a block of fixed height or a line taller than the shorter of page 1's body and the later pages', and a keep-together block or a table's line under its repeated header that the later pages' body cannot hold, though page 1's taller body could; a QR code's text that no version holds at its level, or a square too small for that version's modules to be 0.4 mm, the message naming the size it needs; an EPC QR code past the EPC's 331 bytes or the PSA's modules (below); a QR-bill the slip cannot hold (below); a chart whose words would meet, leave its box or stand in its plot, whose category labels do not fit across their slots, whose plot is too short for two tick labels, whose bars would be narrower than 3.5 pt, or whose pie would be narrower than 24.75 pt, and a bar or a line chart of more than `MAX_CHART_CATEGORIES` categories; a render whose charts together weigh more than `MAX_CHART_DRAWING`, at the chart that crossed it (below); a word that holds a run set below or above the line and is wider than its line (below). |
|
|
198
|
+
| `invalid-asset` | An image's bytes are not the PNG, JPEG or SVG they are declared as, are cut off, or are past the limits: 20 MB, 4096 pixels a side, and for an SVG a mebibyte; a JPEG that PDFKit would read otherwise than its frame header says -- a JPG or DAC segment before the frame header, which PDFKit takes for it, as an arithmetic-coded JPEG may write its DAC segment, a second frame header, or a frame of other than 1, 3 or 4 components, which PDFKit gives no colour space (0031); an SVG is not exactly the drawing report-spec's `cleanSvg` writes (below). A PNG's or a JPEG's structure is read by report-spec's `imageHeader`, which a builder refuses an image a person adds by too, in the same words (0033); whether a PNG's image data inflates to the scanlines its header promises is read here alone, since it needs the platform's decompressor. A host's font `readFont` refuses, one PDFKit would draw as another face, or one asset id handed in two byte strings, naming the asset (0043). |
|
|
106
199
|
| `cancelled` | The signal was aborted. |
|
|
107
|
-
| `unsupported` | What the renderer cannot draw as written: a character the font has no glyph for, a
|
|
200
|
+
| `unsupported` | What the renderer cannot draw as written: text set outside the format's 4 to 96 pt, which the page bound counts each line by, a character the font has no glyph for, a page field's digit included, a character of any script but Latin, Greek and Cyrillic, or a bidirectional control, a `serif` or `mono` token the report does not map or a face a mapped family lacks, text that is not a string, a colour that is not `#rrggbb` in lower case, a QR code's level other than L, M, Q and H, an EPC QR code's caption it does not know, half of a surrogate pair without the other in a code's text, which has no UTF-8, a page field outside the page header and footer, page 1's own header among them, which is drawn before the pages are counted, a page break inside a page region, a keep-together block or a column, a table inside a column, a table row of the wrong number of cells, a block kind, page size or page field it does not know, blocks nested past 16 deep; a run set below or above the line in a word with no text on the line, or set in a way it does not know (below); a QR-bill it cannot draw as SIX prints one (below); an e-invoice it does not know, or what a PDF/A cannot hold, an e-invoice's PDF/A-3b or a PDF/A-2b, a CMYK JPEG or an SVG whose numbers or nesting it cannot hold among them; as a PDF/A-2b, a Factur-X, an XRechnung's copy and a labelled preview (below); a count of kept rows (`keepWithRows`) on a table row that is no group header, outside 2 to `MAX_KEEP_WITH_ROWS`, or past the detail rows under its header, naming the table (0059); and a chart it cannot draw as written: in a page region, page 1's own header among them, past `MAX_TICK_INTERVALS` or `MAX_CHART_SERIES`, with a control character in any of its words, or whose drawing ECharts writes otherwise than it was read to write, or that ECharts lays out through another copy of zrender than the renderer's (below). |
|
|
201
|
+
|
|
202
|
+
## SVG images
|
|
203
|
+
|
|
204
|
+
An image asset may be an SVG
|
|
205
|
+
([0030](../../docs/decisions/0030-an-image-asset-may-be-an-svg-of-drawing-elements-alone-cleaned-once-and-refused-at-print-in-any-other-form.md)),
|
|
206
|
+
which a host approves by cleaning it with report-spec's `cleanSvg`, which
|
|
207
|
+
the runtime hands on, and keeping the bytes it returns. The renderer
|
|
208
|
+
draws an SVG only when report-spec's `checkSvg` finds its bytes already
|
|
209
|
+
exactly what `cleanSvg` writes, and refuses any other as `invalid-asset`,
|
|
210
|
+
naming the asset and what cleaning would change, before pdfmake runs:
|
|
211
|
+
nothing is cleaned, dropped or rewritten at print, so what prints is in
|
|
212
|
+
the form that was approved.
|
|
213
|
+
|
|
214
|
+
- **Drawn as vectors** by the SVG converter pdfmake 0.3.11 vendors,
|
|
215
|
+
svg-to-pdfkit, in the image's box, never as an embedded image: `contain`
|
|
216
|
+
is the converter's `xMidYMid meet`, the whole drawing as large as the box
|
|
217
|
+
allows, centred; `cover` its `xMidYMid slice`, the box filled and the rest
|
|
218
|
+
clipped by the drawing's viewport, which is the box. Nothing is drawn
|
|
219
|
+
outside the box, and a transform on the drawing's root, which the
|
|
220
|
+
cleaner moves inside it, cannot move it out.
|
|
221
|
+
- **Guarded twice behind the check.** The text handed to the converter is
|
|
222
|
+
held to the renderer's own list of the elements a cleaned drawing holds
|
|
223
|
+
(`svg-content.ts`), so that a link, text, an image, `use`, a style sheet,
|
|
224
|
+
a comment or a DOCTYPE never reaches it even were the cleaner wrong; and
|
|
225
|
+
the converter's image and warning callbacks refuse the asset, where the
|
|
226
|
+
converter would open an `<image>`'s file past pdfmake's local access
|
|
227
|
+
policy, or draw on past what it could not read and say so only to the
|
|
228
|
+
console. Neither stops a link, which the converter writes for an `<a>`
|
|
229
|
+
whatever its callbacks say; the check and the list do. The list may
|
|
230
|
+
refuse more than report-spec's tables, never less: a test holds it to
|
|
231
|
+
their `SVG_ELEMENTS`.
|
|
232
|
+
- **Drawn again on every page in the page header or footer.** pdfmake
|
|
233
|
+
lays the page header and footer out for each page, and the converter
|
|
234
|
+
draws the drawing each time: a PNG is embedded once, an SVG grows the PDF
|
|
235
|
+
and the render by its drawing on every page. One in page 1's own header
|
|
236
|
+
is drawn on page 1 alone (0060).
|
|
237
|
+
- **Bounded per render.** What drawing the SVGs costs the renderer is held
|
|
238
|
+
to `MAX_SVG_DRAWING` units of what the converter draws -- lines, curves,
|
|
239
|
+
elements, gradient stops and page-sized transparency groups, each
|
|
240
|
+
weighted by what it was measured to cost beside a line, and every 32
|
|
241
|
+
bytes of the drawing, which pdfmake and the converter read again each
|
|
242
|
+
time it is drawn, whatever it draws -- counting an
|
|
243
|
+
image in the page header or footer on every one of `maxPages`, the pages
|
|
244
|
+
the report may have, which is known before the render, and one in page
|
|
245
|
+
1's own header once: a detailed header logo can
|
|
246
|
+
be refused at a high page limit though the report prints two pages. At
|
|
247
|
+
the budget the renderer spends about what `MAX_IMAGE_DATA`'s largest
|
|
248
|
+
images cost it to decode (`assets.ts` says how both were measured, on
|
|
249
|
+
what and when). What they cost a reader is held
|
|
250
|
+
to what one drawing may cost, which was measured as a page's:
|
|
251
|
+
`MAX_SVG_SEGMENTS` and `MAX_SVG_GROUPS` over every SVG image of the body,
|
|
252
|
+
as though all fell on one page, and those of the page regions, page 1's
|
|
253
|
+
own header's among them. A translucent logo printed twice in the body can
|
|
254
|
+
be refused for it.
|
|
255
|
+
- **Held to PDF/A's limits in a PDF/A** (below), an e-invoice's PDF/A-3b or a
|
|
256
|
+
PDF/A-2b: an SVG whose numbers could pass the integers a PDF/A holds, or
|
|
257
|
+
whose drawing nests deeper than its graphics state may, is refused there
|
|
258
|
+
and drawn in a report drawn as no PDF/A.
|
|
259
|
+
|
|
260
|
+
## Charts
|
|
261
|
+
|
|
262
|
+
A chart block, which the runtime resolves with every word it prints and
|
|
263
|
+
each value's exact digits, is laid out by Apache ECharts 6.1.0 and drawn
|
|
264
|
+
by pdfmake [0058](../../docs/decisions/0058-the-renderer-lays-a-chart-out-with-apache-echarts-and-prints-its-marks-and-its-words-where-echarts-placed-them.md). ECharts places every mark and every word; pdfmake's SVG
|
|
265
|
+
converter draws the marks, and each word prints as pdfmake's text where
|
|
266
|
+
ECharts placed it, so a chart's words are text in the PDF, in the report's
|
|
267
|
+
faces.
|
|
268
|
+
|
|
269
|
+
- **Its words** take the chart's style's font, size -- 8 pt where it names
|
|
270
|
+
none -- weight, slant and colour, the title bold; its alignment is not
|
|
271
|
+
read. Each is measured, for ECharts, in the width pdfmake prints it in,
|
|
272
|
+
in the face the render embeds, through zrender's platform replaced for
|
|
273
|
+
one layout and put back after it, and held to that width once pdfmake
|
|
274
|
+
has measured it.
|
|
275
|
+
- **Its numbers** are the runtime's. ECharts is handed the ticks as the
|
|
276
|
+
axis, each value as its place among them, worked out exactly from its
|
|
277
|
+
decimals, a pie's slices as their exact shares, and every word by its
|
|
278
|
+
index; it rounds, formats and ticks nothing. A slice of no share draws
|
|
279
|
+
nothing and keeps its legend entry, and a pie's arcs are drawn on its
|
|
280
|
+
own circle, within 0.0965 pt.
|
|
281
|
+
- **Its layout** is ECharts' own, three times: where the title and the
|
|
282
|
+
legend stand, then the plot between them, then the plot snapped so that
|
|
283
|
+
every gridline stands on its tick; a pie twice. The renderer reads back
|
|
284
|
+
where every word went, and refuses the chart as `content-too-large`
|
|
285
|
+
where two words would meet, a word would leave the box or stand in the
|
|
286
|
+
plot but a value's label, a category label would not fit across its
|
|
287
|
+
slot, a plot would be too short for two tick labels a line and a
|
|
288
|
+
quarter apart, a bar would be narrower than `MIN_BAR_WIDTH`, 3.5 pt, or
|
|
289
|
+
a pie than `MIN_PIE_DIAMETER`, 24.75 pt, the least at which the
|
|
290
|
+
Studio's Preview draws bars apart, and a slice of one percent as its own
|
|
291
|
+
colour, at 100 % on a screen of device pixel ratio 2, measured. A label is never turned, wrapped or cut, and nothing is
|
|
292
|
+
dropped.
|
|
293
|
+
- **On the page** it is one unbreakable stack, moved whole to the next
|
|
294
|
+
page where it does not fit. A chart with nothing to draw prints its
|
|
295
|
+
title and its empty text, without ECharts.
|
|
296
|
+
|
|
297
|
+
A render's charts are weighed together before any is laid out, and a
|
|
298
|
+
render past `MAX_CHART_DRAWING`, 5,000 units, is refused as
|
|
299
|
+
`content-too-large` at the chart that crossed it. A chart weighs its
|
|
300
|
+
kind's weight, a unit for each series at each category or each slice of a
|
|
301
|
+
pie, and each word it places by what the word is; one with nothing to
|
|
302
|
+
draw weighs nothing. The weights were measured on the render and on
|
|
303
|
+
PDF.js at a load of 12 to 20, a line's again at 3.0 to 3.2, and the
|
|
304
|
+
bound confirmed at quiet loads of 3.3 to 5.6 and 3.0 to 3.9, on one
|
|
305
|
+
machine, as the constant's comment says: two line charts of 8 series
|
|
306
|
+
and 200 categories fit in a render, and three do not.
|
|
307
|
+
The bound holds one layout pass, and a heading kept with a chart makes
|
|
308
|
+
pdfmake lay the document out again for each page it moves the heading
|
|
309
|
+
to, which it does not count.
|
|
310
|
+
|
|
311
|
+
What ECharts writes is held, before anything of it is used, to what
|
|
312
|
+
6.1.0 was seen to write, and refused otherwise as `unsupported`: the
|
|
313
|
+
SVG's elements, attributes, entities, numbers and colours, and every word
|
|
314
|
+
one the block holds. The converter is handed it with no word, no style
|
|
315
|
+
sheet and no clip: ECharts clips every line series to its plot whatever
|
|
316
|
+
the series says, which the converter would draw as a soft mask a reader
|
|
317
|
+
composites for each series, and every value stands inside the ticks and
|
|
318
|
+
a line is stroked with bevelled joins and butt ends, which the reader
|
|
319
|
+
refuses otherwise inside a clip, so the clip cuts nothing and is taken
|
|
320
|
+
out. ECharts and zrender are
|
|
321
|
+
dependencies at exactly 6.1.0, which the repository's licence guard
|
|
322
|
+
admits for this package alone. zrender's platform is one for the process
|
|
323
|
+
or the page, and a host's own ECharts measures through it too; the
|
|
324
|
+
renderer replaces it for one synchronous layout and puts it back.
|
|
325
|
+
ECharts' registries are one for the process or the page too: a
|
|
326
|
+
preprocessor, a processor, a visual, a layout or an update a host
|
|
327
|
+
registers on the ECharts it shares with the renderer runs on the
|
|
328
|
+
renderer's charts, and changes their marks with nothing refused. zrender keeps the widths it measured,
|
|
329
|
+
up to 500 words for each of 100 fonts, after the render, and nothing it
|
|
330
|
+
exports clears them, so a chart's words stay in the process.
|
|
331
|
+
|
|
332
|
+
## QR codes
|
|
333
|
+
|
|
334
|
+
A code is refused, naming it by its id, rather than drawn as one that may
|
|
335
|
+
not scan. What decides its symbol, and every refusal below but the last
|
|
336
|
+
part of the third, is `@formancy/report-runtime`'s `qrSymbol`, the one
|
|
337
|
+
rule the Word writer asks too
|
|
338
|
+
([0074](../../docs/decisions/0074-a-qr-code-and-an-epc-qr-code-are-written-into-a-word-file-and-what-refuses-a-code-stands-below-both-engines.md)):
|
|
339
|
+
the renderer asks it once, when it checks the document, and draws the
|
|
340
|
+
symbol it is handed.
|
|
341
|
+
|
|
342
|
+
| Code | When |
|
|
343
|
+
|---|---|
|
|
344
|
+
| `content-too-large` | Its text is longer than any QR code holds at its level: in byte mode, 2953 bytes at L down to 1273 at H (ISO/IEC 18004, table 7). Past 7089 characters, the digits version 40 holds at L and the most any code holds, it is refused unencoded; a character is a code point, an emoji one. |
|
|
345
|
+
| `content-too-large` | Its modules would be smaller than **0.4 mm**. ISO/IEC 18004 leaves the module size to the application; SIX's Swiss Implementation Guidelines for the QR-bill, version 2.3, section 6.3, require 0.4 mm when printing, taken here as what a printer prints and a phone reads reliably. The same guidelines print a QR-bill's largest code, version 25, at 46 mm without its quiet zone, modules of 0.393 mm: a `qrCode` that size is refused, and a QR-bill's own code is drawn at SIX's size, not held to this floor (below). The message names the smallest square that text needs. |
|
|
346
|
+
| `content-too-large` | It is wider than where it stands, or taller than the body, as an image is. |
|
|
347
|
+
| `unsupported` | Its size is not a positive finite number, its level is not one of L, M, Q and H, or its text is not a string or holds half a surrogate pair. |
|
|
348
|
+
|
|
349
|
+
Empty text is drawn as what it is: a version 1 symbol of no data. ZXing,
|
|
350
|
+
which the tests read codes with, reports no code in it at all. Of the
|
|
351
|
+
runtime's documents, only a preview holds one: it refuses a final render
|
|
352
|
+
whose code has a value that is null, or prints nothing.
|
|
353
|
+
|
|
354
|
+
## EPC QR codes
|
|
355
|
+
|
|
356
|
+
An `epcQrCode` block's payload, which the runtime has written and held to
|
|
357
|
+
the EPC's rules, is encoded by uqr as UTF-8 at level M, its level never
|
|
358
|
+
raised (`boostEcc: false`), in a symbol of version 13 at most (EPC069-12
|
|
359
|
+
2.1), once, when the document is checked, by the runtime's `epcSymbol`,
|
|
360
|
+
which refuses what follows as well (0074). The renderer formats and checks nothing of what the payload says;
|
|
361
|
+
it decides how the code is drawn. Why it is drawn so, and what that costs,
|
|
362
|
+
is [0025](../../docs/decisions/0025-a-report-prints-an-epc-qr-code-held-to-the-epc-rules-beside-the-qr-bill.md).
|
|
363
|
+
|
|
364
|
+
- **Without a caption** it is drawn exactly as a `qrCode` of its payload at
|
|
365
|
+
level M is: the same square, quiet zone and modules, held to the same
|
|
366
|
+
0.4 mm floor. The EPC gives no size, and no frame.
|
|
367
|
+
- **With `caption: 'zahlenMitCode'`** it is drawn as Austria's PSA prints
|
|
368
|
+
one ("QR-Code und BCD Definition", version 3.0, section 5), inside its
|
|
369
|
+
square: modules from 15 to 20 mil (0.381 to 0.508 mm); a frame half a
|
|
370
|
+
module wide, its corners rounded by two modules, its inner edge four
|
|
371
|
+
modules from the symbol on the left, above and below, and its outer edge
|
|
372
|
+
on the square's left and right; and "Zahlen mit Code" at 7 pt in
|
|
373
|
+
Liberation Sans, reading from bottom to top up the right side, beyond
|
|
374
|
+
four modules and in a band of 7 pt, its baseline on the frame's right
|
|
375
|
+
line, which runs along the band's outer edge and is broken a module
|
|
376
|
+
beyond each end of the caption. The caption is centred on the
|
|
377
|
+
symbol and no longer than it, and is text a reader finds. Down, the
|
|
378
|
+
frame is the symbol and nine modules, and stands in the middle of the
|
|
379
|
+
square's height.
|
|
380
|
+
- **The version.** Without a caption, the smallest that holds the payload.
|
|
381
|
+
With one, the least whose modules are at most 20 mil and whose symbol is
|
|
382
|
+
as tall as the caption, or the payload's own when that is larger: in a
|
|
383
|
+
30 mm square, the EPC's first example, version 6, would have modules of
|
|
384
|
+
0.556 mm, and is drawn in version 8 at 0.479 mm. A larger version of the
|
|
385
|
+
same payload at the same level scans to the same bytes.
|
|
386
|
+
- **What the frame and the caption take.** In a 30 mm square (85.04 pt),
|
|
387
|
+
measured on the PDF on 17 October 2026: across, 8.5 modules and the
|
|
388
|
+
caption's 7 pt band, 18.54 pt, so that the symbol is 78.2 % of the side;
|
|
389
|
+
down, nine modules, and 3.16 pt of the square white above the frame and
|
|
390
|
+
below it.
|
|
391
|
+
- **At the corners** the PSA's own figure reaches into the quiet zone: a
|
|
392
|
+
frame four modules from the symbol with corners rounded by two comes
|
|
393
|
+
within 3.49 modules of both of the symbol's edges at each corner, 4.93
|
|
394
|
+
from the corner straight, and so half a module into the square of four
|
|
395
|
+
modules ISO/IEC 18004 keeps quiet. Along the sides the four are white.
|
|
396
|
+
- **The square that prints every payload**, up to version 13's 331 bytes,
|
|
397
|
+
with the caption and without, is 32 mm (90.71 pt) or more: version 13's
|
|
398
|
+
modules are 0.416 mm in it without the caption and 0.381 mm with it. A
|
|
399
|
+
30 mm square refuses a payload past 287 bytes without the caption and
|
|
400
|
+
past 251 with it. The builders' new code is 32 mm for this.
|
|
401
|
+
|
|
402
|
+
The EPC's and the PSA's rules the renderer refuses by are report-spec's,
|
|
403
|
+
handed on by the runtime (`EPC_MAX_BYTES`, `EPC_MAX_VERSION`, `epcModule`,
|
|
404
|
+
`EPC_FRAME`, `EPC_CAPTION`, `epcLeastVersion`, `epcCaptionBreak`); the 0.4
|
|
405
|
+
mm floor and a square wider than where it stands are the renderer's own,
|
|
406
|
+
as for every QR code. The caption's length, 51.36 pt, is its advance in
|
|
407
|
+
Liberation Sans, which a test holds to the PDF. A refusal names the code by its id and never quotes the payload:
|
|
408
|
+
|
|
409
|
+
| Code | When |
|
|
410
|
+
|---|---|
|
|
411
|
+
| `content-too-large` | A payload of more than 331 bytes: refused unencoded when it is longer than that in characters, and once the encoder finds no version up to 13 holds it otherwise. |
|
|
412
|
+
| `content-too-large` | Without a caption, modules smaller than 0.4 mm, the message naming the square the payload needs. |
|
|
413
|
+
| `content-too-large` | With the caption, a square in which no version prints, below 68.06 pt or above 118.6 pt, refused before encoding; or a payload whose version has modules under 15 mil in its square. |
|
|
414
|
+
| `content-too-large` | It is wider than where it stands, or taller than the body, as a QR code is. |
|
|
415
|
+
| `unsupported` | Its size is not a positive finite number, its caption is not one the renderer knows, or its payload is not a string or holds half a surrogate pair. |
|
|
416
|
+
|
|
417
|
+
pdfmake's SVG converter draws the caption, and where it cannot open a face
|
|
418
|
+
it warns and draws the text in the face it drew in last: the renderer
|
|
419
|
+
fails the render instead, as an engine's failure and not a refusal.
|
|
420
|
+
|
|
421
|
+
## QR-bills
|
|
422
|
+
|
|
423
|
+
A document's `paymentPart`, a Swiss QR-bill the runtime has resolved and
|
|
424
|
+
held to SIX's rules, is drawn as SIX's slip: the receipt and the payment
|
|
425
|
+
part, 210 by 105 mm across the foot of the report's last page. The numbers
|
|
426
|
+
are SIX's: its Swiss Implementation Guidelines for the QR-bill, version 2.4
|
|
427
|
+
("IG"), and its Style Guide, version 1.1 ("SG"). Why it is drawn so, and
|
|
428
|
+
what that costs, is [0022](../../docs/decisions/0022-a-report-carries-one-swiss-qr-bill-at-the-foot-of-its-last-page.md).
|
|
429
|
+
|
|
430
|
+
- **Where.** The slip spans the paper's width and ends at its foot (IG 3.1),
|
|
431
|
+
whatever the page margins. It is the last page's footer, drawn there in
|
|
432
|
+
place of the page footer; the page header is drawn as on every page, or
|
|
433
|
+
page 1's own header where the slip is on page 1 of a report that has one.
|
|
434
|
+
The body keeps the slip's room at its end: when the last page has less room
|
|
435
|
+
left, the slip takes a page of its own, which the footers before it count.
|
|
436
|
+
- **The code.** The payload as UTF-8 at level M, in the smallest version
|
|
437
|
+
that holds it and none past 25 (IG 6), 46 mm square without a quiet zone
|
|
438
|
+
of its own, since the slip leaves 5 mm unprinted around it; and the Swiss
|
|
439
|
+
cross over its centre, SIX's logo of 7 mm (IG 6.4.2): a white square of
|
|
440
|
+
7 mm, a black one of 6 mm and a white cross, as schoero's generator draws
|
|
441
|
+
it; manuelbl's draws the same black square and cross on modules it clears
|
|
442
|
+
instead of a white square. It is not held to a `qrCode`'s 0.4 mm floor:
|
|
443
|
+
at version 25 a module is 0.393 mm, at the size SIX prescribes.
|
|
444
|
+
- **The text.** In Liberation Sans, one of the four fonts SIX allows (IG
|
|
445
|
+
3.4): the titles 11 pt bold; the receipt's headings 6 pt bold and its
|
|
446
|
+
values 8 pt, a line every 9 pt; the payment part's 8 and 10 pt, every 11
|
|
447
|
+
pt; a blank line between blocks; the amount 11 pt below its heading on
|
|
448
|
+
the receipt and 13 pt in the payment part (SG 15). Each section stands
|
|
449
|
+
where SG 6 puts it. The additional information is printed in the payment
|
|
450
|
+
part alone (IG 3.6.2), and nothing the bill does not hold has a heading.
|
|
451
|
+
- **The blank fields.** A bill without an amount, or without a debtor, has
|
|
452
|
+
fields for the payer's hand, marked by their corners, 3 mm arms of 0.75 pt:
|
|
453
|
+
30 by 10 and 40 by 15 mm for the amount, 52 by 20 and 65 by 25 mm for the
|
|
454
|
+
debtor (IG 3.5.3, 3.5.4; SG 7).
|
|
455
|
+
- **The lines it is cut along.** One across the paper at the slip's top and
|
|
456
|
+
one between the receipt and the payment part, half a point, each with the
|
|
457
|
+
mark IG 3.7 asks of a line: above the one across, the instruction to
|
|
458
|
+
separate, in the slip's language, 8 pt, centred; on the one down, a
|
|
459
|
+
scissors symbol, filled in black, 2.5 by 3 mm, from 5 mm below the
|
|
460
|
+
slip's top, where the line is broken for it. It keeps inside the 5 mm
|
|
461
|
+
left unprinted beside the line, and is drawn as paths, since Liberation
|
|
462
|
+
Sans has no glyph for U+2702. Its size and place are manuelbl's
|
|
463
|
+
generator's; the drawing is this package's own.
|
|
464
|
+
|
|
465
|
+
A bill is refused, naming `paymentPart` and the field, and never quoting a
|
|
466
|
+
value, which may be a name, an address or an account:
|
|
467
|
+
|
|
468
|
+
| Code | When |
|
|
469
|
+
|---|---|
|
|
470
|
+
| `unsupported` | A payment part of a kind the renderer does not know; a page that is not A4 in portrait; text that is not text, half of a surrogate pair in the payload, or a character Liberation Sans has no glyph for; an amount not written as the slip prints one, or outside report-spec's range, 0.01 to 999 999 999.99; a currency other than CHF and EUR; an address of more than three lines, additional information of more than two, or a value longer than 140 characters, the longest SIX allows. |
|
|
471
|
+
| `content-too-large` | A payload of more than 997 characters, refused unencoded, or whose UTF-8 is more than version 25 holds at level M, 997 bytes (IG 6.2); a page whose top margin, with the page header and the instruction to separate, reaches into the slip, by report-spec's `qrBillPageBreak`, the taller of the page header and page 1's own header where a report has one, since which page is the last is known only once the pages are laid out (0060), and a top margin alone in the editor's words; information taller than its section, 56 mm on the receipt and 85 mm in the payment part (SG 6). |
|
|
472
|
+
|
|
473
|
+
What the slip does not do:
|
|
474
|
+
|
|
475
|
+
- **Shrink its text to fit.** SIX allows the payment part's values from 6 to
|
|
476
|
+
10 pt. The slip prints them at the recommended sizes and refuses
|
|
477
|
+
information taller than its section.
|
|
478
|
+
- **Print alternative procedures, an ultimate creditor, or a bill "not for
|
|
479
|
+
payment".** The format holds none of them.
|
|
480
|
+
- **Decide SIX's rules again.** The runtime holds a bill to them once.
|
|
481
|
+
Where the renderer refuses by one of them -- the page, the currencies,
|
|
482
|
+
the amount's range and the longest value -- it is report-spec's own,
|
|
483
|
+
handed on by the runtime (`QR_BILL_TOP`, `qrBillPageBreak`,
|
|
484
|
+
`QR_BILL_CURRENCIES`, `checkQrBillAmount`,
|
|
485
|
+
`MAX_QR_BILL_ADDITIONAL_INFORMATION`), and the slip is report-spec's
|
|
486
|
+
`QR_BILL_SIZE` at `QR_BILL_TOP`. The renderer decides only what drawing
|
|
487
|
+
decides: the lines an address and the additional information print,
|
|
488
|
+
each section's height, an amount's printed form, and the code's 997.
|
|
489
|
+
|
|
490
|
+
## PDF/A-2b
|
|
491
|
+
|
|
492
|
+
`renderPdf(document, { maxPages, pdfa: '2b' })` draws a final render of a
|
|
493
|
+
report that is no e-invoice as a PDF/A-2b, in either entry
|
|
494
|
+
([0057](../../docs/decisions/0057-a-report-that-is-no-e-invoice-is-drawn-as-a-pdf-a-2b-where-the-host-asks-for-one.md)):
|
|
495
|
+
part 2, which Switzerland's electronic patient record stores a PDF as, at
|
|
496
|
+
the level pdfmake and PDFKit reach. `'2b'` is the one value, and any other
|
|
497
|
+
is a `RangeError` before anything is read. Without `pdfa` nothing changes.
|
|
498
|
+
|
|
499
|
+
- **What it is.** The final pass's definition gets `version` 1.7 and
|
|
500
|
+
`subset` `PDF/A-2b`, so PDFKit writes the pdfaid identification, part 2
|
|
501
|
+
and level B, an sRGB output intent with its ICC profile, and the XMP, as
|
|
502
|
+
it does for an e-invoice's PDF/A-3b. No hook runs, and nothing is
|
|
503
|
+
embedded. The measuring passes have neither version nor subset, and lay
|
|
504
|
+
the pages out as the final pass does, so a PDF/A-2b's pages are the
|
|
505
|
+
plain render's. Level b alone: no structure tree, so no tagged,
|
|
506
|
+
accessible PDF.
|
|
507
|
+
- **Decided once.** `checkPdfA` (`pdfa-check.ts`) decides what a document
|
|
508
|
+
is drawn as -- a Factur-X's PDF/A-3b, the PDF/A-2b a host asked for, or a
|
|
509
|
+
plain PDF -- and the definition, the final pass's hook and the image
|
|
510
|
+
checks read its answer.
|
|
511
|
+
|
|
512
|
+
It refuses, as `unsupported` and before pdfmake sees the document, each
|
|
513
|
+
message saying what to do:
|
|
514
|
+
|
|
515
|
+
- a Factur-X e-invoice and an XRechnung's copy, naming `eInvoice`: a
|
|
516
|
+
Factur-X is drawn as the PDF/A-3b that embeds its XML, which a PDF/A-2b
|
|
517
|
+
may not embed, and an XRechnung's PDF is the copy of the XML a host
|
|
518
|
+
sends, never an archival PDF. Each is rendered without `pdfa`. An
|
|
519
|
+
e-invoice the renderer does not know is refused for what it is, with
|
|
520
|
+
`pdfa` or without;
|
|
521
|
+
- a preview the runtime labels so, naming `pageHeader`: a page header
|
|
522
|
+
whose first block is a paragraph of one run, the runtime's
|
|
523
|
+
`PREVIEW_LABEL` or `E_INVOICE_PREVIEW_LABEL`, in any style. The renderer
|
|
524
|
+
has no mode, so it reads the runtime's label, as it reads an XRechnung's
|
|
525
|
+
copy's, and a PDF/A-2b of a preview would be kept as the report. A
|
|
526
|
+
preview that lacks nothing and is of no e-invoice carries no label, is
|
|
527
|
+
the same document as its final render, as the tests show for the
|
|
528
|
+
quotation, and is drawn as one. A label
|
|
529
|
+
among other runs or below another block is not read;
|
|
530
|
+
- what an e-invoice's PDF/A-3b refuses (below), each message naming the
|
|
531
|
+
PDF/A-2b: a title holding `&`, `<`, `>` or a character XML 1.0 cannot
|
|
532
|
+
write, naming `info.title`, which report-spec refuses in an e-invoice
|
|
533
|
+
report alone, so a report that is none may hold one; a CMYK JPEG, naming
|
|
534
|
+
the image; and an SVG whose numbers could pass the integers a PDF/A
|
|
535
|
+
holds, or whose drawing nests deeper than 28 graphics states, naming it.
|
|
536
|
+
|
|
537
|
+
None of these is said before the render: whether a render is a PDF/A-2b is
|
|
538
|
+
the host's choice at that render, which the builders and the validator do
|
|
539
|
+
not know. What holds by construction: pdfmake embeds a subset of every face
|
|
540
|
+
it draws, and a character a face lacks is refused; the renderer hands
|
|
541
|
+
pdfmake no password, and neither writes JavaScript, an action, a form or
|
|
542
|
+
an annotation; the transparency an RGBA PNG's soft mask or an SVG's group
|
|
543
|
+
makes stands beside the one output intent, which veraPDF's PDF/A-2b
|
|
544
|
+
profile accepted in the gate's variants. What it does not
|
|
545
|
+
hold: the limits of ISO 32000-1 that PDF/A-2 makes rules of, a string's or
|
|
546
|
+
a name's length among them.
|
|
547
|
+
|
|
548
|
+
**What the tests show, and what they do not.** `src/pdfa-check.test.ts`
|
|
549
|
+
holds the decision and every refusal above, each document drawn without
|
|
550
|
+
`pdfa`, and `src/assets.test.ts` and `src/svg-pdfa.test.ts` the images,
|
|
551
|
+
every number of a drawn SVG read back with report-corpus's
|
|
552
|
+
`readPdfNumbers`. `src/pdfa-2b.test.ts` draws every starter that is no
|
|
553
|
+
e-invoice both ways and reads the PDF/A-2b back with readers that are not
|
|
554
|
+
PDFKit: PDF 1.7, its XMP part 2 and B, one sRGB output intent byte for
|
|
555
|
+
byte PDFKit's profile, nothing embedded, no action, form or annotation,
|
|
556
|
+
and the plain render's pages, faces and fonts; and the same bytes twice.
|
|
557
|
+
`src/browser.test.ts` holds the browser entry's to the Node entry's.
|
|
558
|
+
Whether a validator takes the PDF is the e-invoice gate's: veraPDF judges
|
|
559
|
+
every starter so drawn, four variant pages on the quotation's, a page of
|
|
560
|
+
charts among them, and the corpus's two fonts fixtures, with its PDF/A-2b
|
|
561
|
+
profile, and nothing here.
|
|
562
|
+
A customer's template is judged by nothing.
|
|
563
|
+
|
|
564
|
+
## E-invoices
|
|
565
|
+
|
|
566
|
+
A document that carries an e-invoice, `document.eInvoice`, as
|
|
567
|
+
[0027](../../docs/decisions/0027-a-report-carries-one-en-16931-invoice-written-from-the-values-its-page-prints.md) decides, is drawn as what an e-invoice is in
|
|
568
|
+
Germany: a PDF/A-3b that embeds the XML the runtime wrote, the hybrid
|
|
569
|
+
invoice whose XML is the invoice
|
|
570
|
+
([0031](../../docs/decisions/0031-an-e-invoice-is-drawn-as-a-pdf-a-3b-that-embeds-its-xml.md)), in either entry.
|
|
571
|
+
|
|
572
|
+
- **PDF/A-3b, for a Factur-X alone.** Its definition gets `version`
|
|
573
|
+
1.7 and `subset` `PDF/A-3b`, so PDFKit writes the pdfaid identification,
|
|
574
|
+
an sRGB output intent with its ICC profile, and the XMP. Level b is the
|
|
575
|
+
one in reach: level a needs a structure tree pdfmake does not build, and
|
|
576
|
+
PDFKit has no level u. A report that is no e-invoice is drawn as it was,
|
|
577
|
+
or as a PDF/A-2b where its host asks (above).
|
|
578
|
+
- **The file, changed in nothing.** On the final pass alone, through
|
|
579
|
+
PDFKit's own document before it ends, `pdfa.ts` embeds the XML's UTF-8
|
|
580
|
+
bytes as `factur-x.xml`, `text/xml`, related as `Alternative` -- the
|
|
581
|
+
name, relationship and conformance level report-spec gives them
|
|
582
|
+
(`FACTUR_X`, `FACTUR_X_PROFILES`, handed on by the runtime) [S] -- dated
|
|
583
|
+
with the document's creation date, so the same document draws to the
|
|
584
|
+
same bytes. The measuring passes have no file, and lay the pages out as
|
|
585
|
+
the PDF prints them.
|
|
586
|
+
- **The XMP says what the file is.** The fx properties -- the file's
|
|
587
|
+
name, the document type, the version and the conformance level -- and an
|
|
588
|
+
extension schema that declares them are appended to PDFKit's XMP, the
|
|
589
|
+
four descriptions in the renderer's own words.
|
|
590
|
+
- **A preview is a plain PDF.** The runtime writes the XML only in a final
|
|
591
|
+
render; a preview carries none, embeds nothing, and is labelled on every
|
|
592
|
+
page.
|
|
593
|
+
- **An XRechnung's copy is a plain PDF too**
|
|
594
|
+
([0038](../../docs/decisions/0038-a-reports-e-invoice-may-be-an-xrechnung-3-0-whose-xml-a-host-takes-and-whose-pdf-is-its-labelled-copy.md)).
|
|
595
|
+
An XRechnung's XML is the invoice, which a host takes from the resolved
|
|
596
|
+
document and sends; its file, of the kind `xrechnung`, names its syntax,
|
|
597
|
+
guideline and version and nothing to embed it as. Its document is drawn
|
|
598
|
+
as every report is -- no PDF/A, no file, no XMP, a title of any text and
|
|
599
|
+
a CMYK logo drawn -- and its page header opens with the runtime's
|
|
600
|
+
`XRECHNUNG_COPY_PARAGRAPH`, `XRECHNUNG_COPY_LABEL` in small red bold,
|
|
601
|
+
and so does page 1's own header where it has one, so every page says it
|
|
602
|
+
is the copy. Never a ZUGFeRD hybrid of the
|
|
603
|
+
XRECHNUNG profile.
|
|
604
|
+
|
|
605
|
+
It refuses, as `unsupported` and before pdfmake sees the document:
|
|
606
|
+
|
|
607
|
+
- an e-invoice of a kind it does not know, a Factur-X file without its
|
|
608
|
+
kind among them; one whose XML is not text; a Factur-X file whose file
|
|
609
|
+
name, conformance level or relationship is not report-spec's; and an
|
|
610
|
+
XRechnung's whose syntax, version or guideline is not report-spec's;
|
|
611
|
+
- an XRechnung whose page header does not open with the copy's label as
|
|
612
|
+
the runtime writes it, `XRECHNUNG_COPY_PARAGRAPH`, its style and all,
|
|
613
|
+
naming `pageHeader`, or whose first page header, where it has one, does
|
|
614
|
+
not, its none among them, naming `firstPageHeader` (0060): a final picture of an invoice that says nothing of
|
|
615
|
+
what it is, or says it in white or at one point, where PDF.js would
|
|
616
|
+
still find the text. That the label names no font, and prints in the
|
|
617
|
+
renderer's, and that the paper is white, the renderer drawing none, are
|
|
618
|
+
what the check does not read;
|
|
619
|
+
- XML holding a lone surrogate, which an encoder would write as another
|
|
620
|
+
character;
|
|
621
|
+
- a title holding `&`, `<`, `>` or a character XML 1.0 cannot write,
|
|
622
|
+
naming `info.title`: PDFKit writes the title into the XMP unescaped.
|
|
623
|
+
report-spec refuses such a title in an e-invoice report, so only a
|
|
624
|
+
document made otherwise reaches this;
|
|
625
|
+
- a CMYK JPEG in a Factur-X invoice, naming the image: PDFKit draws it in
|
|
626
|
+
DeviceCMYK, which no PDF/A with an sRGB output intent may hold. An
|
|
627
|
+
XRechnung's copy, no PDF/A, draws it. A preview draws it, so a
|
|
628
|
+
template finds out at its final render. The component count is read
|
|
629
|
+
from the frame header PDFKit reads, since a DAC segment shaped as a frame
|
|
630
|
+
of four components once had an RGB JPEG drawn in DeviceCMYK past this
|
|
631
|
+
refusal (measured on 18 October 2026, veraPDF failing it on 6.2.4.3-3),
|
|
632
|
+
and a JPEG PDFKit would read otherwise is refused as `invalid-asset` in
|
|
633
|
+
every report (above);
|
|
634
|
+
- an SVG image whose numbers could pass the 2,147,483,647 a PDF/A-3 holds
|
|
635
|
+
an integer to, or whose drawing svg-to-pdfkit nests more than 28
|
|
636
|
+
graphics states deep, its limit (`svg-pdfa.ts`), naming the image and
|
|
637
|
+
saying what to do. The converter writes a page-sized group's box and a
|
|
638
|
+
gradient's matrix through the inverse of the drawing's transform and
|
|
639
|
+
the box, a gradient's and a clip's in the box it measures on the
|
|
640
|
+
outline, and an outline in points of its own, so a logo whose clip and
|
|
641
|
+
transparency are shrunk a millionfold wrote a box of 78,520,000,000 a
|
|
642
|
+
point square, an e-invoice that said it was a PDF/A and was not, which
|
|
643
|
+
veraPDF 1.30.3 failed, and an arc whose radii the converter grows to
|
|
644
|
+
reach its ends wrote control points of 5 × 10^17 at any size (measured
|
|
645
|
+
on 18 October 2026). The renderer bounds every number the converter will
|
|
646
|
+
write, from report-spec's extent of the drawing -- over every box inside
|
|
647
|
+
a shape's, and the points the converter draws each outline with -- the
|
|
648
|
+
image's box and fit and the page, the image anywhere on it, and refuses
|
|
649
|
+
past `SVG_INTEGER_BOUND`: the integer less a margin of 5.7 % for
|
|
650
|
+
rounding, derived from report-spec's bounds as its comment says.
|
|
651
|
+
report-corpus's `SVG_BOUND`, its groups shrunk so, is drawn on A4 in
|
|
652
|
+
`SVG_BOUND_SIDE`, 41.6 pt square, and refused a hundredth smaller; each
|
|
653
|
+
of report-spec's invented exporter samples the cleaner accepts makes its
|
|
654
|
+
page-sized groups under no shrink and nests five deep at most. The bound
|
|
655
|
+
is not held for matrices built to cancel one another term by term, whose
|
|
656
|
+
products floating point gets wrong.
|
|
657
|
+
|
|
658
|
+
Every other kind of image PDFKit embeds is drawn in an e-invoice, and in
|
|
659
|
+
a PDF/A-2b: report-corpus's `IMAGE_KINDS` -- grey and colour JPEGs, and
|
|
660
|
+
PNGs of every colour type, with alpha, a palette, its transparency or a
|
|
661
|
+
colour key, at 1 and 16 bits, interlaced -- which the e-invoice gate has
|
|
662
|
+
veraPDF and Mustang judge in one e-invoice, and veraPDF in one PDF/A-2b. A colour key is drawn as PDFKit's PNG reader,
|
|
663
|
+
png-js 1.1.0, reads it, in every report since 0.1.0: a grey key by its
|
|
664
|
+
high byte, and an RGB key as twelve numbers where ISO 32000-1 asks two a
|
|
665
|
+
component, which a viewer may ignore; report-corpus's test pins both.
|
|
666
|
+
|
|
667
|
+
A refusal never quotes the XML, which holds names, accounts and VAT
|
|
668
|
+
identifiers. What it leaves as PDFKit 0.19.1 writes it, `src/pdfmake.test.ts`
|
|
669
|
+
pins: the embedded file's `/CheckSum` in 32 hexadecimal digits where ISO
|
|
670
|
+
32000-1 asks for 16 bytes, and one trailer `/ID` for two PDFs of one title
|
|
671
|
+
and creation date.
|
|
672
|
+
|
|
673
|
+
**One file besides the fonts.** PDFKit reads the output intent's profile
|
|
674
|
+
from its own `data/sRGB_IEC61966_2_1.icc` with `fs`, past pdfmake's access
|
|
675
|
+
policy, which governs only what pdfmake opens: a render of a PDF/A, an
|
|
676
|
+
e-invoice's or a PDF/A-2b, reads that file and the fonts, and nothing else
|
|
677
|
+
through `fs.readFileSync`, which a test holds, and one whose profile PDFKit
|
|
678
|
+
cannot read rejects with the file system's error and no PDF. A
|
|
679
|
+
host that bundles the Node entry puts the profile where the bundled
|
|
680
|
+
PDFKit's `__dirname` points, or every PDF/A render fails. The browser
|
|
681
|
+
entry's profile is the base64 copy in pdfmake's browser build, held to the
|
|
682
|
+
same bytes. The profile is the ICC's sRGB2014, which the dependency-licence
|
|
683
|
+
guard admits by its digest, with the ICC's licence sentence a review read
|
|
684
|
+
([0006](../../docs/decisions/0006-dependencies-and-fonts-allow-public-source-and-licensed-production.md)).
|
|
685
|
+
|
|
686
|
+
**What the tests show, and what they do not.** `src/e-invoice.test.ts`
|
|
687
|
+
reads each of the corpus's e-invoice samples back from its PDF with readers
|
|
688
|
+
that are not PDFKit -- the file with PDF.js and pdf-lib, the XMP with saxes
|
|
689
|
+
-- and `src/e-invoice-samples.test.ts` holds what the page prints to the XML
|
|
690
|
+
read out of the same PDF, and the XRechnung sample's copy to the XML its
|
|
691
|
+
document carries; `src/xrechnung.test.ts` reads the copy back as a plain
|
|
692
|
+
PDF that embeds nothing, the label first on every page of one that runs to
|
|
693
|
+
two. `src/svg-pdfa.test.ts` reads every number of an
|
|
694
|
+
SVG's e-invoice back with report-corpus's `readPdfNumbers`, content streams
|
|
695
|
+
included, which veraPDF does not read, and holds the bound to at least
|
|
696
|
+
every number each drawing's PDF writes. Whether a validator takes the PDF
|
|
697
|
+
is the e-invoice gate's: veraPDF and Mustang judge the samples' PDFs
|
|
698
|
+
there, an SVG at every bound among the variants, and nothing here. The fx namespace, prefix and properties rest on a
|
|
699
|
+
transcription of the specification, which no validator reads; the tests
|
|
700
|
+
compare them with the transcription's values, and say so.
|
|
701
|
+
|
|
702
|
+
## Runs below or above the line
|
|
703
|
+
|
|
704
|
+
A paragraph's run set below or above the line
|
|
705
|
+
([0061](../../docs/decisions/0061-a-paragraphs-run-may-be-set-below-or-above-the-line-in-any-character-its-face-draws-and-prints-only-beside-a-run-on-the-line.md))
|
|
706
|
+
is handed to pdfmake with pdfmake's own `sub` or `sup`, and nothing
|
|
707
|
+
else: pdfmake sets it at 0.58 of its paragraph's size, in the paragraph's
|
|
708
|
+
face, and moves its baseline 0.435 of that size up or 0.203 down, the
|
|
709
|
+
runtime's `SHIFTED_SIZE` and `SHIFTED_RISE`. The page bound counts its
|
|
710
|
+
line at that size.
|
|
711
|
+
|
|
712
|
+
pdfmake makes no room for such a run in its line. The renderer makes room
|
|
713
|
+
below a line that holds a run set below the line, for a raised run on the
|
|
714
|
+
next: it asks pdfmake for that run's own line as `LOWERED_LINE` of the
|
|
715
|
+
paragraph's size, 1.218 -- the lowered run's drop, a raised run's rise
|
|
716
|
+
and the small run's own size -- through its `lineHeight`, which pdfmake
|
|
717
|
+
lays out below the baseline, so the two are set solid and their boxes
|
|
718
|
+
meet nowhere. A face whose line is that tall needs none, and a line that
|
|
719
|
+
holds no lowered run is laid out as it was, so a wrapped paragraph's lines
|
|
720
|
+
stand apart unevenly: in Roboto 0.046 of the size farther under such a
|
|
721
|
+
line, in Liberation Serif 0.111. The page bound counts the room.
|
|
722
|
+
|
|
723
|
+
pdfmake lays a line out as tall as its runs' own lines and moves such a
|
|
724
|
+
run only when it draws it, so a line of nothing but such runs would be
|
|
725
|
+
laid out small and drawn into the line before. Once pdfmake has measured a
|
|
726
|
+
paragraph that holds one, and before it lays out a line, the renderer
|
|
727
|
+
reads pdfmake's own words -- the runs it chains with `noNewLine`, which
|
|
728
|
+
no line break separates -- and refuses, naming the paragraph:
|
|
729
|
+
|
|
730
|
+
- **as `unsupported`**, a word that holds such a run and no run on the
|
|
731
|
+
line that prints a character other than a space: a footnote's mark
|
|
732
|
+
after a space, or at the head of its text before one, a word of nothing
|
|
733
|
+
but such runs, and one whose only neighbour prints nothing, as an empty
|
|
734
|
+
field does. A mark is written against its word, or with a no-break
|
|
735
|
+
space, U+00A0. A value read from the data decides it too, in a preview
|
|
736
|
+
as in a final render.
|
|
737
|
+
- **as `content-too-large`**, a word that holds one and is wider than its
|
|
738
|
+
line, measured as pdfmake measures a word that starts one, its leading
|
|
739
|
+
and trailing spaces left out: pdfmake would break it anywhere.
|
|
740
|
+
|
|
741
|
+
A page region's paragraph is read in the pass that measures the regions,
|
|
742
|
+
and a baseline the renderer does not know, or one on a page field, is
|
|
743
|
+
refused as `unsupported` before anything is laid out. The text layer reads
|
|
744
|
+
such a run on the line: PDF.js extracts "H2O", and a search or a copy finds
|
|
745
|
+
the digit as typed. `_inlines`, `noNewLine`, `sup`, `sub`, `width`,
|
|
746
|
+
`leadingCut` and `trailingCut` are pdfmake's own, not its API;
|
|
747
|
+
`pdfmake.test.ts` holds 0.3.11 to them.
|
|
108
748
|
|
|
109
749
|
## Fonts
|
|
110
750
|
|
|
111
|
-
|
|
751
|
+
A report prints its own text in **Roboto 3.014** by default, from pdfmake's
|
|
752
|
+
own package, under
|
|
112
753
|
the SIL Open Font License 1.1, which allows embedding fonts in documents.
|
|
113
754
|
The dependency-licence guard reads that licence from the font files
|
|
114
755
|
themselves ([0006](../../docs/decisions/0006-dependencies-and-fonts-allow-public-source-and-licensed-production.md)).
|
|
@@ -116,19 +757,71 @@ The browser entry's copy in `vfs_fonts.js` is base64 inside a script, which
|
|
|
116
757
|
the guard cannot read; a test holds it to the very bytes of those files.
|
|
117
758
|
Each PDF embeds the subset of each face it uses.
|
|
118
759
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
760
|
+
A report that **maps** a font token to a host's font prints that token's
|
|
761
|
+
text in the host's face instead ([0043](../../docs/decisions/0043-a-report-maps-its-font-tokens-to-fonts-the-host-approved-pinned-by-digest-and-the-renderer-embeds-them.md)).
|
|
762
|
+
The runtime hands the face's bytes over; the renderer reads each with
|
|
763
|
+
report-spec's `readFont` in every render, keeping nothing of it for the
|
|
764
|
+
next, refusing a font it cannot embed as `invalid-asset` naming the asset,
|
|
765
|
+
strips the layout tables fontkit runs at print -- GSUB, GPOS, GDEF, kern and
|
|
766
|
+
`morx`, read from fontkit 2.0.4, which a test pins -- so that a crafted one
|
|
767
|
+
neither hangs nor crashes a render, and embeds the stripped bytes through
|
|
768
|
+
pdfmake's virtual files under names of the render's own, removed from
|
|
769
|
+
pdfmake's storage after each pass. A face a report prints but does not map
|
|
770
|
+
is refused as `unsupported`. Each line counts toward the page limit by the
|
|
771
|
+
face it prints in, a paragraph's by its tallest run's, so a host face of a
|
|
772
|
+
short line lowers the bound of its own text alone; a table's cells are walked
|
|
773
|
+
once, by `styledRows`, for their text, their tallest line and that bound,
|
|
774
|
+
each in the style and at the size `tableContent` prints it in. PDFKit draws
|
|
775
|
+
two faces of one PostScript name as whichever it opened first, so a host face
|
|
776
|
+
is refused as `invalid-asset` where any of its PostScript names is another
|
|
777
|
+
face's of the render with other bytes -- another host asset's, or the
|
|
778
|
+
renderer's own Roboto's or Liberation Sans's, a host's own copy of another
|
|
779
|
+
release among them -- or is `null` or a name every object has, which PDFKit's
|
|
780
|
+
font table holds already (`face-identity.ts`); a face of the renderer's own
|
|
781
|
+
bytes is embedded whole, kerned, and prints as the renderer's. A CFF `.otf`
|
|
782
|
+
is refused until report-spec reads CFF outlines and a PDF/A-3b proves one.
|
|
783
|
+
|
|
784
|
+
- **Latin, Greek and Cyrillic print, and nothing else**, in any face,
|
|
785
|
+
Roboto's included: report-spec's `refusedCharacter` allows the Unicode
|
|
786
|
+
blocks of those scripts and of the punctuation, symbols and marks written
|
|
787
|
+
with them, and refuses every other character as `unsupported` --
|
|
788
|
+
right-to-left, shaping and CJK scripts, simple alphabets such as Armenian
|
|
789
|
+
and Georgian, and the bidirectional controls, which fontkit would draw as
|
|
790
|
+
a space -- since pdfmake reorders nothing and the renderer shapes nothing.
|
|
791
|
+
Every character Roboto maps prints, so a report that maps nothing refuses
|
|
792
|
+
what 0.2.0 refused, in new words for another script.
|
|
793
|
+
|
|
794
|
+
- `sans` is **Roboto** where a report does not map it. **`serif` and `mono`
|
|
795
|
+
are refused** as `unsupported` where a report does not map them: pdfmake
|
|
796
|
+
ships no serif or monospaced font, and printing one in Roboto would be a
|
|
797
|
+
substitution nobody sees until they read the PDF. No serif or mono face is
|
|
798
|
+
shipped; a host supplies them.
|
|
123
799
|
- Bold is **Roboto Medium**, the heaviest face pdfmake ships, and italic is
|
|
124
|
-
Roboto Italic
|
|
800
|
+
Roboto Italic; a host's family maps its own bold and italic faces, and a
|
|
801
|
+
face it does not map is refused, never synthesised.
|
|
125
802
|
- **Every character is held to the face it prints in**, read from the
|
|
126
|
-
faces' own character maps
|
|
127
|
-
|
|
128
|
-
it
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
803
|
+
faces' own character maps by report-spec's `characterMap`, through the
|
|
804
|
+
runtime, as fontkit, which PDFKit lays text out with, reads them
|
|
805
|
+
([0040](../../docs/decisions/0040-a-font-is-read-by-report-specs-own-reader-which-says-what-it-may-be-embedded-as-and-which-characters-it-draws.md)),
|
|
806
|
+
and one without a glyph is refused as
|
|
807
|
+
`unsupported`, naming the face and the code point: pdfmake would print
|
|
808
|
+
it as an empty box, and as U+0000 in the PDF's text. A page number's and
|
|
809
|
+
a page count's digits are held to their paragraph's face too. There is no fallback
|
|
810
|
+
across faces: a character a mapped face lacks is refused, not drawn in
|
|
811
|
+
another. An fr-FR amount, which Intl groups with a narrow no-break space
|
|
812
|
+
(U+202F) that Roboto lacks, is refused where `sans` is Roboto; Swiss
|
|
813
|
+
amounts, de-CH and fr-CH alike, print.
|
|
814
|
+
|
|
815
|
+
A QR-bill's slip and an EPC QR code's caption, and nothing else, print in
|
|
816
|
+
**Liberation Sans 2.1.5**, regular and bold, under the SIL Open Font
|
|
817
|
+
License 1.1: SIX allows Arial, Frutiger, Helvetica and Liberation Sans on a
|
|
818
|
+
slip, and Roboto is none of them; for "Zahlen mit Code" the PSA's figure
|
|
819
|
+
says "Font family Arial o.s. non-serifs". The package ships the two font
|
|
820
|
+
files in `fonts`, with their licence and authors, and the guard reads
|
|
821
|
+
their licence from the files. The browser
|
|
822
|
+
entry's copy is base64 in a chunk the build makes of them, held to their
|
|
823
|
+
bytes by a test. Both faces map every character SIX allows in a bill (IG
|
|
824
|
+
4.1.1), which a test holds too.
|
|
132
825
|
|
|
133
826
|
## What it does not do
|
|
134
827
|
|
|
@@ -149,15 +842,48 @@ Each PDF embeds the subset of each face it uses.
|
|
|
149
842
|
keep-together block, a column or a page region, and not past the end of a
|
|
150
843
|
framed section: a heading that ends a framed section is not kept with
|
|
151
844
|
what follows it.
|
|
845
|
+
- **Say when a group header keeps fewer rows than its row says.** Where
|
|
846
|
+
the rows it keeps do not fit on a page with it under the repeated column
|
|
847
|
+
header, it is kept with as many as fit, and nothing says so: the heights
|
|
848
|
+
are the data's, and a render has no warning to give (0059).
|
|
152
849
|
- **Refuse a spacer at the foot of a page.** One that does not fit what is
|
|
153
850
|
left of a page moves to the next and starts there, without its space.
|
|
154
851
|
- **Measure page regions per page.** They are measured once, every page
|
|
155
852
|
field printed as `maxPages`, so a region that wraps only for some page
|
|
156
|
-
numbers is measured at its widest.
|
|
853
|
+
numbers is measured at its widest. Page 1's own header, which holds no
|
|
854
|
+
page field, is measured once, in a pass of its own.
|
|
855
|
+
- **Print a page number in page 1's own header, or a footer of page 1's
|
|
856
|
+
own.** Page 1's own header is drawn when page 1 is added, before the
|
|
857
|
+
pages are counted, and page 1 prints the page footer every page prints.
|
|
858
|
+
Where page 1's own header is taller than the page header, a block page
|
|
859
|
+
1's body cannot hold whole starts page 2, page 1 printing its header
|
|
860
|
+
alone; where it is shorter, or none, a kept block, a table's line under
|
|
861
|
+
its repeated header or an image that only page 1's taller body could
|
|
862
|
+
hold is refused, even in a report that would end on page 1, since where
|
|
863
|
+
a block lands is known only once the body is laid out; and where a
|
|
864
|
+
report has one, the page header is still measured and held to leaving a
|
|
865
|
+
body, though a report of one page prints it on no page
|
|
866
|
+
([0060](../../docs/decisions/0060-a-reports-first-page-may-print-a-header-of-its-own-or-none-in-place-of-the-page-header.md)).
|
|
867
|
+
- **Make room above a raised run.** pdfmake places a line's baseline its
|
|
868
|
+
tallest ascender down, and room above cannot be asked of it, so a raised
|
|
869
|
+
run reaches above its line's text: by the corpus's boxes it stays clear
|
|
870
|
+
of the line above in Roboto and Liberation Serif, and in a host face
|
|
871
|
+
whose line is shorter than 1.099 ems it is not proved. A line that holds
|
|
872
|
+
a lowered run is given room below it (above); the glyphs themselves can
|
|
873
|
+
still touch an accent, which the boxes do not see.
|
|
874
|
+
- **Draw an SVG as a browser does, compared.** That the PDF shows what a
|
|
875
|
+
browser draws of the same cleaned drawing is held by report-spec's allow
|
|
876
|
+
lists and by review; no browser's rendering is compared with the PDF.
|
|
157
877
|
- **Decode a JPEG's scan.** Its structure is checked, up to the scan, and a
|
|
158
878
|
corrupt scan inside a well-formed JPEG reaches the PDF. A PNG's image data
|
|
159
879
|
is inflated and checked; data with bytes after its zlib stream is refused,
|
|
160
880
|
as the Compression Streams standard refuses it.
|
|
881
|
+
- **Mark a QR code's text as UTF-8.** uqr writes no ECI designator, and
|
|
882
|
+
ISO/IEC 18004 reads byte mode as ISO/IEC 8859-1 unless one says
|
|
883
|
+
otherwise, so a reader that keeps to that default reads an umlaut as two
|
|
884
|
+
Latin-1 characters. ZXing, which the tests read codes with, reads them
|
|
885
|
+
as UTF-8, as the tests show for umlauts, the euro sign and an emoji; what
|
|
886
|
+
every phone does, nothing here shows.
|
|
161
887
|
|
|
162
888
|
## Tests
|
|
163
889
|
|
|
@@ -165,16 +891,160 @@ Each PDF embeds the subset of each face it uses.
|
|
|
165
891
|
`@formancy/report-corpus` and proves each PDF with the corpus's checks, or
|
|
166
892
|
holds a refusal to the one the fixture allows
|
|
167
893
|
([0003](../../docs/decisions/0003-a-rendered-report-is-proved-on-the-pdf-it-produced.md)).
|
|
168
|
-
These are the tests decision 0005 names
|
|
894
|
+
These are the tests decision 0005 names; the corpus's kept rows' fixture
|
|
895
|
+
(`KEEP_WITH_FIXTURES`), which the trial never drew, is rendered beside
|
|
896
|
+
them, and `group-rows.test.ts` holds a group header to the rows its row
|
|
897
|
+
keeps, or as many as fit, on the PDFs (0059); and so is its kept headings'
|
|
898
|
+
fixture (`KEPT_HEADING_FIXTURES`), a heading and a run of two over tables
|
|
899
|
+
longer than any plausible page, the heading on the page of the line it
|
|
900
|
+
stands under and of its table's first row, the run on its table's first
|
|
901
|
+
row's, which `flow.test.ts` holds through a framed section and over a kept
|
|
902
|
+
group header too (0011). Each block kind is read back from
|
|
169
903
|
the PDF it produced: its text and images with PDF.js, through the corpus's
|
|
170
904
|
reader, and its lines, rectangles, clips and text colours from the PDF's own
|
|
171
905
|
content streams (`src/testing/drawing.ts`), which PDF.js's text does not
|
|
172
|
-
show.
|
|
173
|
-
|
|
906
|
+
show. A QR code is read as a scanner reads it: the page drawn by PDF.js and
|
|
907
|
+
decoded by ZXing (`readCodes` in the corpus), for its text, its bytes, its
|
|
908
|
+
level, its version and where it stands. `starters.test.ts` resolves the
|
|
909
|
+
starters with the runtime and proves their PDFs: plan 7's three swept
|
|
910
|
+
across page ends, the invoice down to its bill's code, decoded from the
|
|
911
|
+
page and asking for the total the page prints, the euro invoice down
|
|
912
|
+
to its EPC QR code, decoded from the page, asking for that total and
|
|
913
|
+
standing beside the payment details it holds, each printed in plain
|
|
914
|
+
text, and the site visit generated from a formancy form down to each
|
|
915
|
+
answer's line, each box and each finding's row, over pages at 80 of
|
|
916
|
+
them. `order-confirmation.test.ts` proves the order confirmation's three
|
|
917
|
+
tables line by line across its page break, each total recomputed in
|
|
918
|
+
BigInt, its letterhead on page 1 alone and its running header from page
|
|
919
|
+
2, and its third delivery's header kept on page 2 with its first three
|
|
920
|
+
lines where kept with one it stands at the foot of page 1; and
|
|
921
|
+
`product-data-sheet.test.ts` the product data sheet in each of its four
|
|
922
|
+
languages, its powers, index and marks off the line by the corpus's
|
|
923
|
+
`shiftedRuns`, every line of the page in that language and its values as
|
|
924
|
+
that locale writes them
|
|
925
|
+
([0064](../../docs/decisions/0064-an-order-confirmation-and-a-product-data-sheet-are-starters-that-print-what-0059-to-0063-added.md)).
|
|
926
|
+
`payment-reminder.test.ts` proves the payment reminder in each of its
|
|
927
|
+
four languages: both tables line by line, every total and what is due
|
|
928
|
+
recomputed in BigInt, the slip's headings in that language alone, and its
|
|
929
|
+
code, decoded from the page, asking for what is due by the reminder's
|
|
930
|
+
reference; and, with forty invoices more, its running header from page 2
|
|
931
|
+
and its slip on the last page alone
|
|
932
|
+
([0066](../../docs/decisions/0066-a-payment-reminder-is-a-starter-that-pays-the-balance-of-a-customers-overdue-invoices-by-a-qr-bill-in-the-customers-language.md)).
|
|
933
|
+
`sales-report.test.ts` proves the monthly sales report: its table line by
|
|
934
|
+
line across its page break, every total recomputed in BigInt; each bar
|
|
935
|
+
measured against the gridlines the PDF draws, as tall as its product
|
|
936
|
+
line's total and labelled with the digits that group's total prints in
|
|
937
|
+
the table; each slice by the turn it sweeps, its legend entry its region's
|
|
938
|
+
total and its share rounded once; and its letterhead on page 1 alone and
|
|
939
|
+
its running header from page 2
|
|
940
|
+
([0067](../../docs/decisions/0067-a-monthly-sales-report-is-a-starter-whose-bar-chart-and-pie-print-the-totals-its-table-prints.md)).
|
|
941
|
+
`samples.test.ts` does the same for the corpus's invoice samples,
|
|
942
|
+
the invoice in German, French, Italian and English: one page each, its
|
|
943
|
+
totals in its locale's format, its slip's headings in its language and in
|
|
944
|
+
no other's, and its code asking for the total it prints.
|
|
945
|
+
`languages.test.ts` prints the corpus's invoice written in the same four
|
|
946
|
+
languages as one report, in each of them: that language's words and none
|
|
947
|
+
of the report's own in another, its total in that locale's format, its
|
|
948
|
+
slip's headings in its language and its code carrying the message in it,
|
|
949
|
+
each PDF equal by `inflatedDigest` to the invoice written in that language
|
|
950
|
+
alone; and every starter and sample prints the same bytes with its own
|
|
951
|
+
locale named as with none. The renderer draws a translated report's
|
|
952
|
+
document as it draws any other, and the PDF names no language of its own
|
|
953
|
+
([0063](../../docs/decisions/0063-a-reports-own-words-are-written-in-each-language-it-declares-and-a-render-names-the-one-it-prints-in.md)).
|
|
954
|
+
`euro-samples.test.ts` does it for the euro invoice's samples, the
|
|
955
|
+
starter and the invoice from Austria, France, Italy, Spain, the
|
|
956
|
+
Netherlands and Ireland: one page each, its totals as `Intl` formats its
|
|
957
|
+
locale at the rate the test states, its code decoded at level M asking
|
|
958
|
+
for the total it prints, with the payment details beside it, and
|
|
959
|
+
Austria's caption on the Austrian sample alone
|
|
960
|
+
([0028](../../docs/decisions/0028-the-euro-invoice-comes-as-samples-from-six-euro-countries-and-an-epc-qr-code-page-shows-them.md)).
|
|
961
|
+
Each of them, and `e-invoice-samples.test.ts` for the e-invoice samples'
|
|
962
|
+
PDF/A-3b, finds the firm's mark at the head of the page
|
|
963
|
+
(`src/testing/letterhead.ts`): one drawing in its blue at the margins'
|
|
964
|
+
corner, 15 mm square, in its two paints, with no image and no text beside
|
|
965
|
+
it or in the 12 pt under it; by the pixels, nothing of it past its box;
|
|
966
|
+
and the quotation's on its first page alone
|
|
967
|
+
([0032](../../docs/decisions/0032-the-invoices-and-the-quotation-print-one-invented-wordless-mark-at-the-top-left-of-their-first-page.md)).
|
|
968
|
+
`epc-qr-code.test.ts` proves EPC QR codes on their PDF: the EPC's
|
|
969
|
+
examples decoded byte for byte at level M, and 331 bytes in version 13;
|
|
970
|
+
the caption read back by PDF.js, its text, its turn, its face and its
|
|
971
|
+
length; the frame from the content stream; and the quiet zone, the
|
|
972
|
+
frame's line and the caption from the pixels. `qr-bill.test.ts` and
|
|
973
|
+
`qr-bill-pages.test.ts` prove a QR-bill's slip on its PDF: SIX's
|
|
974
|
+
examples, resolved by the runtime, decoded byte for byte; every heading
|
|
975
|
+
and value read back where SIX puts it, at its size and in its face; the
|
|
976
|
+
lines, the scissors on the line down, the corner marks and the cross from
|
|
977
|
+
the content stream, and the cross from the pixels too; and the page the
|
|
978
|
+
slip goes on.
|
|
979
|
+
|
|
980
|
+
`svg.test.ts` proves an SVG image on its PDF: no image embedded, a clip of
|
|
981
|
+
exactly its box with its paths inside it in its own colours, read by the
|
|
982
|
+
corpus's reader through the transparency groups a clip path draws into,
|
|
983
|
+
`contain`'s proportions, and from the pixels `cover` and a
|
|
984
|
+
root's transform painting nothing outside the box, each beside the same
|
|
985
|
+
drawing as it came, which does; and the budget at its bound and one past
|
|
986
|
+
it, an image in the page header or footer counted on every page. `svg-threats.test.ts`
|
|
987
|
+
refuses each hazard svg-to-pdfkit meets in an SVG as it came -- a local
|
|
988
|
+
image, text, a style sheet, an entity, a `use` fan-out, a link -- before
|
|
989
|
+
pdfmake runs, and shows each guard behind the check hold without it; holds
|
|
990
|
+
the renderer's list of elements to report-spec's; and draws a drawing
|
|
991
|
+
shrunk, and a gradient composed, to the bound, where past it PDFKit threw
|
|
992
|
+
from inside pdfmake, refusing the drawing past it as `invalid-asset`.
|
|
993
|
+
`svg-converter.test.ts` draws every drawing the tests hold, and a thousand
|
|
994
|
+
seeded mutations of them the cleaner accepts, through the converter's
|
|
995
|
+
throwing callbacks; holds the worst drawing the bounds accept, rasterised
|
|
996
|
+
page-wide, to sixteen times a starter page rasterised in the same process;
|
|
997
|
+
and holds the converter's colour names to the cleaner's.
|
|
998
|
+
`pdfmake.test.ts` pins the converter as it is: the file it opens past the
|
|
999
|
+
access policy, the link it writes whatever its callbacks say, the drawing
|
|
1000
|
+
xmldoc hands it, its warnings, its clip and the page-sized groups it draws
|
|
1001
|
+
for every reference. Every SVG the renderer draws in these tests is held
|
|
1002
|
+
to carrying no annotation.
|
|
1003
|
+
|
|
1004
|
+
`first-page-header.test.ts` proves page 1's own header on its PDF (0060):
|
|
1005
|
+
each of the corpus's `FIRST_PAGE_FIXTURES`, a long grouped table under a
|
|
1006
|
+
letterhead taller than the page header, under none and under a header
|
|
1007
|
+
shorter than it, reads on page 1, line by line and drawing by drawing,
|
|
1008
|
+
exactly as the same document under a page header like its own, and on every
|
|
1009
|
+
later page exactly as under the page header alone; a one-page report prints
|
|
1010
|
+
its own header and the page header nowhere, with a QR-bill's slip under it,
|
|
1011
|
+
its code decoded; a heading kept with the next block stays first on page 1,
|
|
1012
|
+
a kept block page 1 cannot hold starts page 2 whole, and the slip is held
|
|
1013
|
+
below the taller header; its SVG counts once, and a heading in it names no
|
|
1014
|
+
destination. `pdfmake.test.ts` pins what that rests on: the background laid
|
|
1015
|
+
out in a box as large as the page, an empty node's top margin moving the
|
|
1016
|
+
next line up or down by itself, a header function returning null, as the
|
|
1017
|
+
renderer's does, and a table's fill painted under its own text beneath the
|
|
1018
|
+
background.
|
|
1019
|
+
|
|
1020
|
+
`shifted.test.ts` proves a run set below or above the line on its PDF,
|
|
1021
|
+
read from PDF.js's runs and not through a line reader: drawn at
|
|
1022
|
+
`SHIFTED_SIZE` of its paragraph's size and moved by `SHIFTED_RISE`, to a
|
|
1023
|
+
hundredth of a point, in Roboto at two sizes and in the corpus's
|
|
1024
|
+
Liberation Serif; clear of the lines above and below where its paragraph
|
|
1025
|
+
wraps; in page 1's own header, page 1's body starting below the room its
|
|
1026
|
+
lowered run takes (0060); in the language a render names, the translation's
|
|
1027
|
+
word at the baseline the report's run sets (0063); and each way a word
|
|
1028
|
+
could leave it alone on a line refused, naming the paragraph, a page
|
|
1029
|
+
region's and page 1's own header's among them. The corpus's
|
|
1030
|
+
`SHIFTED_FIXTURES` are rendered and proved with the rest, page 1 held to
|
|
1031
|
+
its own header's runs and every later page to the page header's.
|
|
1032
|
+
|
|
1033
|
+
`fonts.test.ts` reads the faces the package embeds, Roboto's four and
|
|
1034
|
+
Liberation Sans's two, through report-spec's reader to the values measured
|
|
1035
|
+
from their files, holds the line constants to their own lines, and holds
|
|
1036
|
+
the reader to fontkit, loaded from the PDFKit pdfmake loads: every code
|
|
1037
|
+
point of each face mapped alike; every recorded length of the tables the
|
|
1038
|
+
reader reads, of two of them, refused or drawn alike, glyph for glyph; and
|
|
1039
|
+
seeded corruptions of the same two, each refused by the reader or mapped
|
|
1040
|
+
and named alike and embedded by PDFKit (0040). It holds glyphs.ts to the
|
|
1041
|
+
reader on a face whose maps disagree, too.
|
|
174
1042
|
|
|
175
|
-
`scripts/readme-pictures.ts` draws the
|
|
176
|
-
|
|
177
|
-
|
|
1043
|
+
`scripts/readme-pictures.ts` draws the pictures of the starters and of
|
|
1044
|
+
both invoices' samples with PDF.js, which the repository's
|
|
1045
|
+
[`docs/starters.md`](../../docs/starters.md) shows and its README two of,
|
|
1046
|
+
and `pictures.test.ts` holds each to the page it was drawn from: its lines and where each
|
|
1047
|
+
starts, and its drawings, path by path:
|
|
178
1048
|
|
|
179
1049
|
```bash
|
|
180
1050
|
pnpm --filter @formancy/report-render-pdf exec unrun scripts/readme-pictures.ts
|