@formancy/report-render-pdf 0.1.0 → 0.2.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 +447 -14
- package/dist/bill-fonts-CFSgj0iW.mjs +18 -0
- package/dist/bill-fonts-CFSgj0iW.mjs.map +1 -0
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.mjs +54 -13
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +30 -15
- package/dist/index.mjs.map +1 -1
- package/dist/render-DkPoADDg.mjs +3228 -0
- package/dist/render-DkPoADDg.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 +9 -7
- package/dist/render-Bs7DXIYJ.mjs +0 -1943
- package/dist/render-Bs7DXIYJ.mjs.map +0 -1
package/NOTICE
CHANGED
|
@@ -7,3 +7,11 @@ This product is distributed under the Formancy Report Source-Available Licence
|
|
|
7
7
|
This product includes software developed by the formancy project
|
|
8
8
|
(https://github.com/sharkysan/formancy.ai), licensed under the Apache License,
|
|
9
9
|
Version 2.0. Those packages keep their licence; nothing here changes it.
|
|
10
|
+
|
|
11
|
+
@formancy/report-render-pdf includes the Liberation Sans fonts, version
|
|
12
|
+
2.1.5, Regular and Bold, in its fonts directory and, as base64, in its
|
|
13
|
+
browser build. Digitized data copyright (c) 2010 Google Corporation, with
|
|
14
|
+
Reserved Font Arimo, Tinos and Cousine. Copyright (c) 2012 Red Hat, Inc.,
|
|
15
|
+
with Reserved Font Name Liberation. They are licensed under the SIL Open
|
|
16
|
+
Font License, Version 1.1, whose text travels with them as
|
|
17
|
+
fonts/LICENSE-LiberationSans.txt; nothing here changes it.
|
package/README.md
CHANGED
|
@@ -39,20 +39,33 @@ document's own (`info.creationDate`), and nothing else in the file varies.
|
|
|
39
39
|
|
|
40
40
|
| Entry | pdfmake | Fonts |
|
|
41
41
|
|---|---|---|
|
|
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
|
|
42
|
+
| `@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 an e-invoice, PDFKit reads its ICC profile from its own package (below) |
|
|
43
|
+
| `@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
44
|
|
|
45
45
|
The two entries share everything but the build of pdfmake and where the
|
|
46
46
|
fonts come from: the checks, the measuring passes and the document
|
|
47
47
|
definitions are one module both import. The browser entry touches no file
|
|
48
|
-
system and imports no `node:` module.
|
|
48
|
+
system and imports no `node:` module. Liberation Sans reaches it through a
|
|
49
|
+
dynamic import alone, so an app's bundler puts it in a chunk that a host
|
|
50
|
+
which never prints a bill or a captioned EPC QR code never loads, which a
|
|
51
|
+
test holds. An import that fails is not kept: the document it failed for
|
|
52
|
+
rejects with its error, and the next bill or caption imports the chunk
|
|
53
|
+
again; once it has loaded, nothing imports it again. The Node entry keeps
|
|
54
|
+
its reads of the font files the same way, so a file it could not open just
|
|
55
|
+
then fails the render that asked for it and no render after.
|
|
56
|
+
Whether a browser fetches a chunk again after a failure, or a chunk a
|
|
57
|
+
deploy removed is still there, is not the renderer's to decide: a page
|
|
58
|
+
reload is.
|
|
49
59
|
|
|
50
60
|
What the tests show about the browser entry, run in Node: for every fixture
|
|
51
61
|
in the corpus it hands pdfmake the definitions the Node entry does, its PDFs
|
|
52
62
|
pass the corpus's checks, it places every run and image where the Node entry
|
|
53
63
|
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
|
-
|
|
64
|
+
build in a browser. That is the Studio's browser gate's to check:
|
|
65
|
+
`apps/studio/scripts/browser-test.mjs`, in CI's `browser` job, prints
|
|
66
|
+
every starter through this entry in Chromium and reads its text back, and
|
|
67
|
+
no other browser runs it
|
|
68
|
+
([0013](../../docs/decisions/0013-the-studio-is-the-same-room-and-its-pictures-are-taken-by-a-script.md)).
|
|
56
69
|
|
|
57
70
|
pdfmake is one configuration per process, or per page in a browser: fonts
|
|
58
71
|
and access policies are global to it. The renderer sets its own again
|
|
@@ -79,7 +92,28 @@ Every block of the resolved document:
|
|
|
79
92
|
- **Images**, in a box the layout reserves whole: `contain` draws all of
|
|
80
93
|
the image at its proportions, as large as the box allows, centred in it;
|
|
81
94
|
`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.
|
|
95
|
+
the size it is shown at, after its Exif orientation. An SVG is drawn as
|
|
96
|
+
vectors (below), fitted by its viewBox.
|
|
97
|
+
- **QR codes** (ISO/IEC 18004), encoded by [uqr](https://github.com/unjs/uqr)
|
|
98
|
+
in the smallest version that holds their text at the level asked for,
|
|
99
|
+
never a higher level, and drawn in vectors as a square exactly their size:
|
|
100
|
+
white, with the quiet zone of four modules inside it, and the dark
|
|
101
|
+
modules one black path over it, filled once, so that no viewer draws a
|
|
102
|
+
light line where two rows meet inside a pixel. The square is an SVG,
|
|
103
|
+
which pdfmake places as it places an image: a path in a pdfmake 0.3.11
|
|
104
|
+
canvas is never moved to where the canvas stands. Its text is never
|
|
105
|
+
printed, so it is not held to the font: umlauts, the euro sign and emoji
|
|
106
|
+
are encoded as UTF-8, and text of digits or capitals alone in the denser
|
|
107
|
+
modes for them. Each code is encoded once, when the document is checked,
|
|
108
|
+
and that symbol is the one every pass and every page draws. A heading
|
|
109
|
+
kept with the next block is kept with a code as with an image. What a
|
|
110
|
+
large code adds to a render's time and to the PDF, and what the one fill
|
|
111
|
+
costs against a rectangle for each run, is measured in
|
|
112
|
+
[0020](../../docs/decisions/0020-a-qr-code-is-drawn-from-its-own-matrix-and-refused-where-it-may-not-scan.md).
|
|
113
|
+
- **EPC QR codes** (EPC069-12 version 3.1), the code a SEPA credit
|
|
114
|
+
transfer is initiated from: the runtime's payload encoded as a QR code's
|
|
115
|
+
text is, at level M and in version 13 at most, and drawn as a QR code
|
|
116
|
+
is, or in Austria's frame with "Zahlen mit Code" beside it (below).
|
|
83
117
|
- **Rules**, at their thickness and colour, across the width they stand in,
|
|
84
118
|
with 3 pt above and below.
|
|
85
119
|
- **Rectangles**, filled, outlined or both, their outline drawn inside the
|
|
@@ -95,16 +129,335 @@ Every block of the resolved document:
|
|
|
95
129
|
- **The page header and footer**, on every page, with the page number and
|
|
96
130
|
the page count. The body is laid out between them, after both are
|
|
97
131
|
measured.
|
|
132
|
+
- **A QR-bill's payment part**, the receipt and the payment part with its
|
|
133
|
+
Swiss QR Code, across the foot of the last page in place of its page
|
|
134
|
+
footer (below).
|
|
98
135
|
|
|
99
136
|
## What it refuses
|
|
100
137
|
|
|
101
138
|
| Code | When |
|
|
102
139
|
|---|---|
|
|
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
|
|
140
|
+
| `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. |
|
|
141
|
+
| `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; 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; 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). |
|
|
142
|
+
| `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. |
|
|
106
143
|
| `cancelled` | The signal was aborted. |
|
|
107
|
-
| `unsupported` | What the renderer cannot draw as written: a character the font has no glyph for, a font other than `sans`, text that is not a string, a colour that is not `#rrggbb` in lower case, a page field outside the page header and footer, 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. |
|
|
144
|
+
| `unsupported` | What the renderer cannot draw as written: a character the font has no glyph for, a font other than `sans`, 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, 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 QR-bill it cannot draw as SIX prints one (below); an e-invoice it does not know, or one its PDF/A-3b cannot hold, a CMYK JPEG or an SVG whose numbers or nesting it cannot hold among them (below). |
|
|
145
|
+
|
|
146
|
+
## SVG images
|
|
147
|
+
|
|
148
|
+
An image asset may be an SVG
|
|
149
|
+
([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)),
|
|
150
|
+
which a host approves by cleaning it with report-spec's `cleanSvg`, which
|
|
151
|
+
the runtime hands on, and keeping the bytes it returns. The renderer
|
|
152
|
+
draws an SVG only when report-spec's `checkSvg` finds its bytes already
|
|
153
|
+
exactly what `cleanSvg` writes, and refuses any other as `invalid-asset`,
|
|
154
|
+
naming the asset and what cleaning would change, before pdfmake runs:
|
|
155
|
+
nothing is cleaned, dropped or rewritten at print, so what prints is in
|
|
156
|
+
the form that was approved.
|
|
157
|
+
|
|
158
|
+
- **Drawn as vectors** by the SVG converter pdfmake 0.3.11 vendors,
|
|
159
|
+
svg-to-pdfkit, in the image's box, never as an embedded image: `contain`
|
|
160
|
+
is the converter's `xMidYMid meet`, the whole drawing as large as the box
|
|
161
|
+
allows, centred; `cover` its `xMidYMid slice`, the box filled and the rest
|
|
162
|
+
clipped by the drawing's viewport, which is the box. Nothing is drawn
|
|
163
|
+
outside the box, and a transform on the drawing's root, which the
|
|
164
|
+
cleaner moves inside it, cannot move it out.
|
|
165
|
+
- **Guarded twice behind the check.** The text handed to the converter is
|
|
166
|
+
held to the renderer's own list of the elements a cleaned drawing holds
|
|
167
|
+
(`svg-content.ts`), so that a link, text, an image, `use`, a style sheet,
|
|
168
|
+
a comment or a DOCTYPE never reaches it even were the cleaner wrong; and
|
|
169
|
+
the converter's image and warning callbacks refuse the asset, where the
|
|
170
|
+
converter would open an `<image>`'s file past pdfmake's local access
|
|
171
|
+
policy, or draw on past what it could not read and say so only to the
|
|
172
|
+
console. Neither stops a link, which the converter writes for an `<a>`
|
|
173
|
+
whatever its callbacks say; the check and the list do. The list may
|
|
174
|
+
refuse more than report-spec's tables, never less: a test holds it to
|
|
175
|
+
their `SVG_ELEMENTS`.
|
|
176
|
+
- **Drawn again on every page in a page region.** pdfmake lays the page
|
|
177
|
+
header and footer out for each page, and the converter draws the drawing
|
|
178
|
+
each time: a PNG is embedded once, an SVG grows the PDF and the render
|
|
179
|
+
by its drawing on every page.
|
|
180
|
+
- **Bounded per render.** What drawing the SVGs costs the renderer is held
|
|
181
|
+
to `MAX_SVG_DRAWING` units of what the converter draws -- lines, curves,
|
|
182
|
+
elements, gradient stops and page-sized transparency groups, each
|
|
183
|
+
weighted by what it was measured to cost beside a line, and every 32
|
|
184
|
+
bytes of the drawing, which pdfmake and the converter read again each
|
|
185
|
+
time it is drawn, whatever it draws -- counting an
|
|
186
|
+
image in a page region on every one of `maxPages`, the pages the report
|
|
187
|
+
may have, which is known before the render: a detailed header logo can
|
|
188
|
+
be refused at a high page limit though the report prints two pages. At
|
|
189
|
+
the budget the renderer spends about what `MAX_IMAGE_DATA`'s largest
|
|
190
|
+
images cost it to decode (`assets.ts` says how both were measured, on
|
|
191
|
+
what and when). What they cost a reader is held
|
|
192
|
+
to what one drawing may cost, which was measured as a page's:
|
|
193
|
+
`MAX_SVG_SEGMENTS` and `MAX_SVG_GROUPS` over every SVG image of the body,
|
|
194
|
+
as though all fell on one page, and those of the page regions. A
|
|
195
|
+
translucent logo printed twice in the body can be refused for it.
|
|
196
|
+
- **Held to PDF/A in an e-invoice** (below): an SVG whose numbers could
|
|
197
|
+
pass the integers a PDF/A-3 holds, or whose drawing nests deeper than
|
|
198
|
+
its graphics state may, is refused there and drawn in any other report.
|
|
199
|
+
|
|
200
|
+
## QR codes
|
|
201
|
+
|
|
202
|
+
A code is refused, naming it by its id, rather than drawn as one that may
|
|
203
|
+
not scan:
|
|
204
|
+
|
|
205
|
+
| Code | When |
|
|
206
|
+
|---|---|
|
|
207
|
+
| `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. |
|
|
208
|
+
| `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. |
|
|
209
|
+
| `content-too-large` | It is wider than where it stands, or taller than the body, as an image is. |
|
|
210
|
+
| `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. |
|
|
211
|
+
|
|
212
|
+
Empty text is drawn as what it is: a version 1 symbol of no data. ZXing,
|
|
213
|
+
which the tests read codes with, reports no code in it at all. Of the
|
|
214
|
+
runtime's documents, only a preview holds one: it refuses a final render
|
|
215
|
+
whose code has a value that is null, or prints nothing.
|
|
216
|
+
|
|
217
|
+
## EPC QR codes
|
|
218
|
+
|
|
219
|
+
An `epcQrCode` block's payload, which the runtime has written and held to
|
|
220
|
+
the EPC's rules, is encoded by uqr as UTF-8 at level M, its level never
|
|
221
|
+
raised (`boostEcc: false`), in a symbol of version 13 at most (EPC069-12
|
|
222
|
+
2.1), once, when the document is checked. The renderer formats and checks nothing of what the payload says;
|
|
223
|
+
it decides how the code is drawn. Why it is drawn so, and what that costs,
|
|
224
|
+
is [0025](../../docs/decisions/0025-a-report-prints-an-epc-qr-code-held-to-the-epc-rules-beside-the-qr-bill.md).
|
|
225
|
+
|
|
226
|
+
- **Without a caption** it is drawn exactly as a `qrCode` of its payload at
|
|
227
|
+
level M is: the same square, quiet zone and modules, held to the same
|
|
228
|
+
0.4 mm floor. The EPC gives no size, and no frame.
|
|
229
|
+
- **With `caption: 'zahlenMitCode'`** it is drawn as Austria's PSA prints
|
|
230
|
+
one ("QR-Code und BCD Definition", version 3.0, section 5), inside its
|
|
231
|
+
square: modules from 15 to 20 mil (0.381 to 0.508 mm); a frame half a
|
|
232
|
+
module wide, its corners rounded by two modules, its inner edge four
|
|
233
|
+
modules from the symbol on the left, above and below, and its outer edge
|
|
234
|
+
on the square's left and right; and "Zahlen mit Code" at 7 pt in
|
|
235
|
+
Liberation Sans, reading from bottom to top up the right side, beyond
|
|
236
|
+
four modules and in a band of 7 pt, its baseline on the frame's right
|
|
237
|
+
line, which runs along the band's outer edge and is broken a module
|
|
238
|
+
beyond each end of the caption. The caption is centred on the
|
|
239
|
+
symbol and no longer than it, and is text a reader finds. Down, the
|
|
240
|
+
frame is the symbol and nine modules, and stands in the middle of the
|
|
241
|
+
square's height.
|
|
242
|
+
- **The version.** Without a caption, the smallest that holds the payload.
|
|
243
|
+
With one, the least whose modules are at most 20 mil and whose symbol is
|
|
244
|
+
as tall as the caption, or the payload's own when that is larger: in a
|
|
245
|
+
30 mm square, the EPC's first example, version 6, would have modules of
|
|
246
|
+
0.556 mm, and is drawn in version 8 at 0.479 mm. A larger version of the
|
|
247
|
+
same payload at the same level scans to the same bytes.
|
|
248
|
+
- **What the frame and the caption take.** In a 30 mm square (85.04 pt),
|
|
249
|
+
measured on the PDF on 17 October 2026: across, 8.5 modules and the
|
|
250
|
+
caption's 7 pt band, 18.54 pt, so that the symbol is 78.2 % of the side;
|
|
251
|
+
down, nine modules, and 3.16 pt of the square white above the frame and
|
|
252
|
+
below it.
|
|
253
|
+
- **At the corners** the PSA's own figure reaches into the quiet zone: a
|
|
254
|
+
frame four modules from the symbol with corners rounded by two comes
|
|
255
|
+
within 3.49 modules of both of the symbol's edges at each corner, 4.93
|
|
256
|
+
from the corner straight, and so half a module into the square of four
|
|
257
|
+
modules ISO/IEC 18004 keeps quiet. Along the sides the four are white.
|
|
258
|
+
- **The square that prints every payload**, up to version 13's 331 bytes,
|
|
259
|
+
with the caption and without, is 32 mm (90.71 pt) or more: version 13's
|
|
260
|
+
modules are 0.416 mm in it without the caption and 0.381 mm with it. A
|
|
261
|
+
30 mm square refuses a payload past 287 bytes without the caption and
|
|
262
|
+
past 251 with it. The builders' new code is 32 mm for this.
|
|
263
|
+
|
|
264
|
+
The EPC's and the PSA's rules the renderer refuses by are report-spec's,
|
|
265
|
+
handed on by the runtime (`EPC_MAX_BYTES`, `EPC_MAX_VERSION`, `epcModule`,
|
|
266
|
+
`EPC_FRAME`, `EPC_CAPTION`, `epcLeastVersion`, `epcCaptionBreak`); the 0.4
|
|
267
|
+
mm floor and a square wider than where it stands are the renderer's own,
|
|
268
|
+
as for every QR code. The caption's length, 51.36 pt, is its advance in
|
|
269
|
+
Liberation Sans, which a test holds to the PDF. A refusal names the code by its id and never quotes the payload:
|
|
270
|
+
|
|
271
|
+
| Code | When |
|
|
272
|
+
|---|---|
|
|
273
|
+
| `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. |
|
|
274
|
+
| `content-too-large` | Without a caption, modules smaller than 0.4 mm, the message naming the square the payload needs. |
|
|
275
|
+
| `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. |
|
|
276
|
+
| `content-too-large` | It is wider than where it stands, or taller than the body, as a QR code is. |
|
|
277
|
+
| `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. |
|
|
278
|
+
|
|
279
|
+
pdfmake's SVG converter draws the caption, and where it cannot open a face
|
|
280
|
+
it warns and draws the text in the face it drew in last: the renderer
|
|
281
|
+
fails the render instead, as an engine's failure and not a refusal.
|
|
282
|
+
|
|
283
|
+
## QR-bills
|
|
284
|
+
|
|
285
|
+
A document's `paymentPart`, a Swiss QR-bill the runtime has resolved and
|
|
286
|
+
held to SIX's rules, is drawn as SIX's slip: the receipt and the payment
|
|
287
|
+
part, 210 by 105 mm across the foot of the report's last page. The numbers
|
|
288
|
+
are SIX's: its Swiss Implementation Guidelines for the QR-bill, version 2.4
|
|
289
|
+
("IG"), and its Style Guide, version 1.1 ("SG"). Why it is drawn so, and
|
|
290
|
+
what that costs, is [0022](../../docs/decisions/0022-a-report-carries-one-swiss-qr-bill-at-the-foot-of-its-last-page.md).
|
|
291
|
+
|
|
292
|
+
- **Where.** The slip spans the paper's width and ends at its foot (IG 3.1),
|
|
293
|
+
whatever the page margins. It is the last page's footer, drawn there in
|
|
294
|
+
place of the page footer; the page header is drawn as on every page. The
|
|
295
|
+
body keeps the slip's room at its end: when the last page has less room
|
|
296
|
+
left, the slip takes a page of its own, which the footers before it count.
|
|
297
|
+
- **The code.** The payload as UTF-8 at level M, in the smallest version
|
|
298
|
+
that holds it and none past 25 (IG 6), 46 mm square without a quiet zone
|
|
299
|
+
of its own, since the slip leaves 5 mm unprinted around it; and the Swiss
|
|
300
|
+
cross over its centre, SIX's logo of 7 mm (IG 6.4.2): a white square of
|
|
301
|
+
7 mm, a black one of 6 mm and a white cross, as schoero's generator draws
|
|
302
|
+
it; manuelbl's draws the same black square and cross on modules it clears
|
|
303
|
+
instead of a white square. It is not held to a `qrCode`'s 0.4 mm floor:
|
|
304
|
+
at version 25 a module is 0.393 mm, at the size SIX prescribes.
|
|
305
|
+
- **The text.** In Liberation Sans, one of the four fonts SIX allows (IG
|
|
306
|
+
3.4): the titles 11 pt bold; the receipt's headings 6 pt bold and its
|
|
307
|
+
values 8 pt, a line every 9 pt; the payment part's 8 and 10 pt, every 11
|
|
308
|
+
pt; a blank line between blocks; the amount 11 pt below its heading on
|
|
309
|
+
the receipt and 13 pt in the payment part (SG 15). Each section stands
|
|
310
|
+
where SG 6 puts it. The additional information is printed in the payment
|
|
311
|
+
part alone (IG 3.6.2), and nothing the bill does not hold has a heading.
|
|
312
|
+
- **The blank fields.** A bill without an amount, or without a debtor, has
|
|
313
|
+
fields for the payer's hand, marked by their corners, 3 mm arms of 0.75 pt:
|
|
314
|
+
30 by 10 and 40 by 15 mm for the amount, 52 by 20 and 65 by 25 mm for the
|
|
315
|
+
debtor (IG 3.5.3, 3.5.4; SG 7).
|
|
316
|
+
- **The lines it is cut along.** One across the paper at the slip's top and
|
|
317
|
+
one between the receipt and the payment part, half a point, each with the
|
|
318
|
+
mark IG 3.7 asks of a line: above the one across, the instruction to
|
|
319
|
+
separate, in the slip's language, 8 pt, centred; on the one down, a
|
|
320
|
+
scissors symbol, filled in black, 2.5 by 3 mm, from 5 mm below the
|
|
321
|
+
slip's top, where the line is broken for it. It keeps inside the 5 mm
|
|
322
|
+
left unprinted beside the line, and is drawn as paths, since Liberation
|
|
323
|
+
Sans has no glyph for U+2702. Its size and place are manuelbl's
|
|
324
|
+
generator's; the drawing is this package's own.
|
|
325
|
+
|
|
326
|
+
A bill is refused, naming `paymentPart` and the field, and never quoting a
|
|
327
|
+
value, which may be a name, an address or an account:
|
|
328
|
+
|
|
329
|
+
| Code | When |
|
|
330
|
+
|---|---|
|
|
331
|
+
| `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. |
|
|
332
|
+
| `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`, 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). |
|
|
333
|
+
|
|
334
|
+
What the slip does not do:
|
|
335
|
+
|
|
336
|
+
- **Shrink its text to fit.** SIX allows the payment part's values from 6 to
|
|
337
|
+
10 pt. The slip prints them at the recommended sizes and refuses
|
|
338
|
+
information taller than its section.
|
|
339
|
+
- **Print alternative procedures, an ultimate creditor, or a bill "not for
|
|
340
|
+
payment".** The format holds none of them.
|
|
341
|
+
- **Decide SIX's rules again.** The runtime holds a bill to them once.
|
|
342
|
+
Where the renderer refuses by one of them -- the page, the currencies,
|
|
343
|
+
the amount's range and the longest value -- it is report-spec's own,
|
|
344
|
+
handed on by the runtime (`QR_BILL_TOP`, `qrBillPageBreak`,
|
|
345
|
+
`QR_BILL_CURRENCIES`, `checkQrBillAmount`,
|
|
346
|
+
`MAX_QR_BILL_ADDITIONAL_INFORMATION`), and the slip is report-spec's
|
|
347
|
+
`QR_BILL_SIZE` at `QR_BILL_TOP`. The renderer decides only what drawing
|
|
348
|
+
decides: the lines an address and the additional information print,
|
|
349
|
+
each section's height, an amount's printed form, and the code's 997.
|
|
350
|
+
|
|
351
|
+
## E-invoices
|
|
352
|
+
|
|
353
|
+
A document that carries an e-invoice, `document.eInvoice`, as
|
|
354
|
+
[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
|
|
355
|
+
Germany: a PDF/A-3b that embeds the XML the runtime wrote, the hybrid
|
|
356
|
+
invoice whose XML is the invoice
|
|
357
|
+
([0031](../../docs/decisions/0031-an-e-invoice-is-drawn-as-a-pdf-a-3b-that-embeds-its-xml.md)), in either entry.
|
|
358
|
+
|
|
359
|
+
- **PDF/A-3b, for an e-invoice alone.** Its definition gets `version`
|
|
360
|
+
1.7 and `subset` `PDF/A-3b`, so PDFKit writes the pdfaid identification,
|
|
361
|
+
an sRGB output intent with its ICC profile, and the XMP. Level b is the
|
|
362
|
+
one in reach: level a needs a structure tree pdfmake does not build, and
|
|
363
|
+
PDFKit has no level u. Every other report is drawn as it was.
|
|
364
|
+
- **The file, changed in nothing.** On the final pass alone, through
|
|
365
|
+
PDFKit's own document before it ends, `pdfa.ts` embeds the XML's UTF-8
|
|
366
|
+
bytes as `factur-x.xml`, `text/xml`, related as `Alternative` -- the
|
|
367
|
+
name, relationship and conformance level report-spec gives them
|
|
368
|
+
(`FACTUR_X`, `FACTUR_X_PROFILES`, handed on by the runtime) [S] -- dated
|
|
369
|
+
with the document's creation date, so the same document draws to the
|
|
370
|
+
same bytes. The measuring passes have no file, and lay the pages out as
|
|
371
|
+
the PDF prints them.
|
|
372
|
+
- **The XMP says what the file is.** The fx properties -- the file's
|
|
373
|
+
name, the document type, the version and the conformance level -- and an
|
|
374
|
+
extension schema that declares them are appended to PDFKit's XMP, the
|
|
375
|
+
four descriptions in the renderer's own words.
|
|
376
|
+
- **A preview is a plain PDF.** The runtime writes the XML only in a final
|
|
377
|
+
render; a preview carries none, embeds nothing, and is labelled on every
|
|
378
|
+
page.
|
|
379
|
+
|
|
380
|
+
It refuses, as `unsupported` and before pdfmake sees the document:
|
|
381
|
+
|
|
382
|
+
- an e-invoice whose XML is not text, or whose file name, conformance level
|
|
383
|
+
or relationship is not report-spec's;
|
|
384
|
+
- XML holding a lone surrogate, which an encoder would write as another
|
|
385
|
+
character;
|
|
386
|
+
- a title holding `&`, `<`, `>` or a character XML 1.0 cannot write,
|
|
387
|
+
naming `info.title`: PDFKit writes the title into the XMP unescaped.
|
|
388
|
+
report-spec refuses such a title in an e-invoice report, so only a
|
|
389
|
+
document made otherwise reaches this;
|
|
390
|
+
- a CMYK JPEG, naming the image: PDFKit draws it in DeviceCMYK, which no
|
|
391
|
+
PDF/A with an sRGB output intent may hold. A preview draws it, so a
|
|
392
|
+
template finds out at its final render. The component count is read
|
|
393
|
+
from the frame header PDFKit reads, since a DAC segment shaped as a frame
|
|
394
|
+
of four components once had an RGB JPEG drawn in DeviceCMYK past this
|
|
395
|
+
refusal (measured on 18 October 2026, veraPDF failing it on 6.2.4.3-3),
|
|
396
|
+
and a JPEG PDFKit would read otherwise is refused as `invalid-asset` in
|
|
397
|
+
every report (above);
|
|
398
|
+
- an SVG image whose numbers could pass the 2,147,483,647 a PDF/A-3 holds
|
|
399
|
+
an integer to, or whose drawing svg-to-pdfkit nests more than 28
|
|
400
|
+
graphics states deep, its limit (`svg-pdfa.ts`), naming the image and
|
|
401
|
+
saying what to do. The converter writes a page-sized group's box and a
|
|
402
|
+
gradient's matrix through the inverse of the drawing's transform and
|
|
403
|
+
the box, a gradient's and a clip's in the box it measures on the
|
|
404
|
+
outline, and an outline in points of its own, so a logo whose clip and
|
|
405
|
+
transparency are shrunk a millionfold wrote a box of 78,520,000,000 a
|
|
406
|
+
point square, an e-invoice that said it was a PDF/A and was not, which
|
|
407
|
+
veraPDF 1.30.3 failed, and an arc whose radii the converter grows to
|
|
408
|
+
reach its ends wrote control points of 5 × 10^17 at any size (measured
|
|
409
|
+
on 18 October 2026). The renderer bounds every number the converter will
|
|
410
|
+
write, from report-spec's extent of the drawing -- over every box inside
|
|
411
|
+
a shape's, and the points the converter draws each outline with -- the
|
|
412
|
+
image's box and fit and the page, the image anywhere on it, and refuses
|
|
413
|
+
past `SVG_INTEGER_BOUND`: the integer less a margin of 5.7 % for
|
|
414
|
+
rounding, derived from report-spec's bounds as its comment says.
|
|
415
|
+
report-corpus's `SVG_BOUND`, its groups shrunk so, is drawn on A4 in
|
|
416
|
+
`SVG_BOUND_SIDE`, 41.6 pt square, and refused a hundredth smaller; each
|
|
417
|
+
of report-spec's invented exporter samples the cleaner accepts makes its
|
|
418
|
+
page-sized groups under no shrink and nests five deep at most. The bound
|
|
419
|
+
is not held for matrices built to cancel one another term by term, whose
|
|
420
|
+
products floating point gets wrong.
|
|
421
|
+
|
|
422
|
+
Every other kind of image PDFKit embeds is drawn in an e-invoice:
|
|
423
|
+
report-corpus's `IMAGE_KINDS` -- grey and colour JPEGs, and PNGs of every
|
|
424
|
+
colour type, with alpha, a palette, its transparency or a colour key, at
|
|
425
|
+
1 and 16 bits, interlaced -- which the e-invoice gate has veraPDF and
|
|
426
|
+
Mustang judge in one. A colour key is drawn as PDFKit's PNG reader,
|
|
427
|
+
png-js 1.1.0, reads it, in every report since 0.1.0: a grey key by its
|
|
428
|
+
high byte, and an RGB key as twelve numbers where ISO 32000-1 asks two a
|
|
429
|
+
component, which a viewer may ignore; report-corpus's test pins both.
|
|
430
|
+
|
|
431
|
+
A refusal never quotes the XML, which holds names, accounts and VAT
|
|
432
|
+
identifiers. What it leaves as PDFKit 0.19.1 writes it, `src/pdfmake.test.ts`
|
|
433
|
+
pins: the embedded file's `/CheckSum` in 32 hexadecimal digits where ISO
|
|
434
|
+
32000-1 asks for 16 bytes, and one trailer `/ID` for two PDFs of one title
|
|
435
|
+
and creation date.
|
|
436
|
+
|
|
437
|
+
**One file besides the fonts.** PDFKit reads the output intent's profile
|
|
438
|
+
from its own `data/sRGB_IEC61966_2_1.icc` with `fs`, past pdfmake's access
|
|
439
|
+
policy, which governs only what pdfmake opens: a render of an e-invoice
|
|
440
|
+
reads that file and the fonts, and nothing else through
|
|
441
|
+
`fs.readFileSync`, which a test holds. A
|
|
442
|
+
host that bundles the Node entry puts the profile where the bundled
|
|
443
|
+
PDFKit's `__dirname` points, or every e-invoice render fails. The browser
|
|
444
|
+
entry's profile is the base64 copy in pdfmake's browser build, held to the
|
|
445
|
+
same bytes. The profile is the ICC's sRGB2014, which the dependency-licence
|
|
446
|
+
guard admits by its digest, with the ICC's licence sentence a review read
|
|
447
|
+
([0006](../../docs/decisions/0006-dependencies-and-fonts-allow-public-source-and-licensed-production.md)).
|
|
448
|
+
|
|
449
|
+
**What the tests show, and what they do not.** `src/e-invoice.test.ts`
|
|
450
|
+
reads each of the corpus's e-invoice samples back from its PDF with readers
|
|
451
|
+
that are not PDFKit -- the file with PDF.js and pdf-lib, the XMP with saxes
|
|
452
|
+
-- and `src/e-invoice-samples.test.ts` holds what the page prints to the XML
|
|
453
|
+
read out of the same PDF. `src/svg-pdfa.test.ts` reads every number of an
|
|
454
|
+
SVG's e-invoice back with report-corpus's `readPdfNumbers`, content streams
|
|
455
|
+
included, which veraPDF does not read, and holds the bound to at least
|
|
456
|
+
every number each drawing's PDF writes. Whether a validator takes the PDF
|
|
457
|
+
is the e-invoice gate's: veraPDF and Mustang judge the samples' PDFs
|
|
458
|
+
there, an SVG at every bound among the variants, and nothing here. The fx namespace, prefix and properties rest on a
|
|
459
|
+
transcription of the specification, which no validator reads; the tests
|
|
460
|
+
compare them with the transcription's values, and say so.
|
|
108
461
|
|
|
109
462
|
## Fonts
|
|
110
463
|
|
|
@@ -130,6 +483,17 @@ Each PDF embeds the subset of each face it uses.
|
|
|
130
483
|
fr-FR amount, which Intl groups with a narrow no-break space (U+202F)
|
|
131
484
|
that Roboto lacks. Swiss amounts, de-CH and fr-CH alike, print.
|
|
132
485
|
|
|
486
|
+
A QR-bill's slip and an EPC QR code's caption, and nothing else, print in
|
|
487
|
+
**Liberation Sans 2.1.5**, regular and bold, under the SIL Open Font
|
|
488
|
+
License 1.1: SIX allows Arial, Frutiger, Helvetica and Liberation Sans on a
|
|
489
|
+
slip, and Roboto is none of them; for "Zahlen mit Code" the PSA's figure
|
|
490
|
+
says "Font family Arial o.s. non-serifs". The package ships the two font
|
|
491
|
+
files in `fonts`, with their licence and authors, and the guard reads
|
|
492
|
+
their licence from the files. The browser
|
|
493
|
+
entry's copy is base64 in a chunk the build makes of them, held to their
|
|
494
|
+
bytes by a test. Both faces map every character SIX allows in a bill (IG
|
|
495
|
+
4.1.1), which a test holds too.
|
|
496
|
+
|
|
133
497
|
## What it does not do
|
|
134
498
|
|
|
135
499
|
- **Cancel inside a pass.** pdfmake measures, lays out and writes a
|
|
@@ -154,10 +518,19 @@ Each PDF embeds the subset of each face it uses.
|
|
|
154
518
|
- **Measure page regions per page.** They are measured once, every page
|
|
155
519
|
field printed as `maxPages`, so a region that wraps only for some page
|
|
156
520
|
numbers is measured at its widest.
|
|
521
|
+
- **Draw an SVG as a browser does, compared.** That the PDF shows what a
|
|
522
|
+
browser draws of the same cleaned drawing is held by report-spec's allow
|
|
523
|
+
lists and by review; no browser's rendering is compared with the PDF.
|
|
157
524
|
- **Decode a JPEG's scan.** Its structure is checked, up to the scan, and a
|
|
158
525
|
corrupt scan inside a well-formed JPEG reaches the PDF. A PNG's image data
|
|
159
526
|
is inflated and checked; data with bytes after its zlib stream is refused,
|
|
160
527
|
as the Compression Streams standard refuses it.
|
|
528
|
+
- **Mark a QR code's text as UTF-8.** uqr writes no ECI designator, and
|
|
529
|
+
ISO/IEC 18004 reads byte mode as ISO/IEC 8859-1 unless one says
|
|
530
|
+
otherwise, so a reader that keeps to that default reads an umlaut as two
|
|
531
|
+
Latin-1 characters. ZXing, which the tests read codes with, reads them
|
|
532
|
+
as UTF-8, as the tests show for umlauts, the euro sign and an emoji; what
|
|
533
|
+
every phone does, nothing here shows.
|
|
161
534
|
|
|
162
535
|
## Tests
|
|
163
536
|
|
|
@@ -169,12 +542,72 @@ These are the tests decision 0005 names. Each block kind is read back from
|
|
|
169
542
|
the PDF it produced: its text and images with PDF.js, through the corpus's
|
|
170
543
|
reader, and its lines, rectangles, clips and text colours from the PDF's own
|
|
171
544
|
content streams (`src/testing/drawing.ts`), which PDF.js's text does not
|
|
172
|
-
show.
|
|
173
|
-
|
|
545
|
+
show. A QR code is read as a scanner reads it: the page drawn by PDF.js and
|
|
546
|
+
decoded by ZXing (`readCodes` in the corpus), for its text, its bytes, its
|
|
547
|
+
level, its version and where it stands. `starters.test.ts` resolves the
|
|
548
|
+
starters with the runtime and proves their PDFs: plan 7's three swept
|
|
549
|
+
across page ends, the invoice down to its bill's code, decoded from the
|
|
550
|
+
page and asking for the total the page prints, and the euro invoice down
|
|
551
|
+
to its EPC QR code, decoded from the page, asking for that total and
|
|
552
|
+
standing beside the payment details it holds, each printed in plain
|
|
553
|
+
text. `samples.test.ts` does the same for the corpus's invoice samples,
|
|
554
|
+
the invoice in German, French, Italian and English: one page each, its
|
|
555
|
+
totals in its locale's format, its slip's headings in its language and in
|
|
556
|
+
no other's, and its code asking for the total it prints.
|
|
557
|
+
`euro-samples.test.ts` does it for the euro invoice's samples, the
|
|
558
|
+
starter and the invoice from Austria, France, Italy, Spain, the
|
|
559
|
+
Netherlands and Ireland: one page each, its totals as `Intl` formats its
|
|
560
|
+
locale at the rate the test states, its code decoded at level M asking
|
|
561
|
+
for the total it prints, with the payment details beside it, and
|
|
562
|
+
Austria's caption on the Austrian sample alone
|
|
563
|
+
([0028](../../docs/decisions/0028-the-euro-invoice-comes-as-samples-from-six-euro-countries-and-an-epc-qr-code-page-shows-them.md)).
|
|
564
|
+
Each of them, and `e-invoice-samples.test.ts` for the e-invoice samples'
|
|
565
|
+
PDF/A-3b, finds the firm's mark at the head of the page
|
|
566
|
+
(`src/testing/letterhead.ts`): one drawing in its blue at the margins'
|
|
567
|
+
corner, 15 mm square, in its two paints, with no image and no text beside
|
|
568
|
+
it or in the 12 pt under it; by the pixels, nothing of it past its box;
|
|
569
|
+
and the quotation's on its first page alone
|
|
570
|
+
([0032](../../docs/decisions/0032-the-invoices-and-the-quotation-print-one-invented-wordless-mark-at-the-top-left-of-their-first-page.md)).
|
|
571
|
+
`epc-qr-code.test.ts` proves EPC QR codes on their PDF: the EPC's
|
|
572
|
+
examples decoded byte for byte at level M, and 331 bytes in version 13;
|
|
573
|
+
the caption read back by PDF.js, its text, its turn, its face and its
|
|
574
|
+
length; the frame from the content stream; and the quiet zone, the
|
|
575
|
+
frame's line and the caption from the pixels. `qr-bill.test.ts` and
|
|
576
|
+
`qr-bill-pages.test.ts` prove a QR-bill's slip on its PDF: SIX's
|
|
577
|
+
examples, resolved by the runtime, decoded byte for byte; every heading
|
|
578
|
+
and value read back where SIX puts it, at its size and in its face; the
|
|
579
|
+
lines, the scissors on the line down, the corner marks and the cross from
|
|
580
|
+
the content stream, and the cross from the pixels too; and the page the
|
|
581
|
+
slip goes on.
|
|
582
|
+
|
|
583
|
+
`svg.test.ts` proves an SVG image on its PDF: no image embedded, a clip of
|
|
584
|
+
exactly its box with its paths inside it in its own colours, read by the
|
|
585
|
+
corpus's reader through the transparency groups a clip path draws into,
|
|
586
|
+
`contain`'s proportions, and from the pixels `cover` and a
|
|
587
|
+
root's transform painting nothing outside the box, each beside the same
|
|
588
|
+
drawing as it came, which does; and the budget at its bound and one past
|
|
589
|
+
it, an image in a page region counted on every page. `svg-threats.test.ts`
|
|
590
|
+
refuses each hazard svg-to-pdfkit meets in an SVG as it came -- a local
|
|
591
|
+
image, text, a style sheet, an entity, a `use` fan-out, a link -- before
|
|
592
|
+
pdfmake runs, and shows each guard behind the check hold without it; holds
|
|
593
|
+
the renderer's list of elements to report-spec's; and draws a drawing
|
|
594
|
+
shrunk, and a gradient composed, to the bound, where past it PDFKit threw
|
|
595
|
+
from inside pdfmake, refusing the drawing past it as `invalid-asset`.
|
|
596
|
+
`svg-converter.test.ts` draws every drawing the tests hold, and a thousand
|
|
597
|
+
seeded mutations of them the cleaner accepts, through the converter's
|
|
598
|
+
throwing callbacks; holds the worst drawing the bounds accept, rasterised
|
|
599
|
+
page-wide, to sixteen times a starter page rasterised in the same process;
|
|
600
|
+
and holds the converter's colour names to the cleaner's.
|
|
601
|
+
`pdfmake.test.ts` pins the converter as it is: the file it opens past the
|
|
602
|
+
access policy, the link it writes whatever its callbacks say, the drawing
|
|
603
|
+
xmldoc hands it, its warnings, its clip and the page-sized groups it draws
|
|
604
|
+
for every reference. Every SVG the renderer draws in these tests is held
|
|
605
|
+
to carrying no annotation.
|
|
174
606
|
|
|
175
607
|
`scripts/readme-pictures.ts` draws the repository README's pictures of the
|
|
176
|
-
starters with PDF.js, and `pictures.test.ts`
|
|
177
|
-
page it was drawn from:
|
|
608
|
+
starters and of both invoices' samples with PDF.js, and `pictures.test.ts`
|
|
609
|
+
holds each to the page it was drawn from: its lines and where each
|
|
610
|
+
starts, and its drawings, path by path:
|
|
178
611
|
|
|
179
612
|
```bash
|
|
180
613
|
pnpm --filter @formancy/report-render-pdf exec unrun scripts/readme-pictures.ts
|