html2pdf-accessible 0.0.0-stage → 0.1.5
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/LICENSE +21 -0
- package/README.md +219 -2
- package/THIRD_PARTY_NOTICES.md +15 -0
- package/deps/canvaskit-pdf/CHROMIUM-LICENSE +27 -0
- package/deps/canvaskit-pdf/LICENSE +29 -0
- package/deps/canvaskit-pdf/README.md +35 -0
- package/deps/canvaskit-pdf/THIRD_PARTY_LICENSES.txt +2152 -0
- package/deps/canvaskit-pdf/bin/canvaskit.js +215 -0
- package/deps/canvaskit-pdf/chromium-license-source.json +5 -0
- package/deps/canvaskit-pdf/package.json +22 -0
- package/deps/canvaskit-pdf/pdf_bindings.cpp +179 -0
- package/deps/canvaskit-pdf/provenance.json +37 -0
- package/deps/canvaskit-pdf/types/google-types.d.ts +4948 -0
- package/deps/canvaskit-pdf/types/index.d.ts +48 -0
- package/lib/html2pdf-accessible.cjs.js +3 -0
- package/lib/html2pdf-accessible.cjs.js.LICENSE.txt +14 -0
- package/lib/html2pdf-accessible.cjs.js.map +1 -0
- package/lib/html2pdf-accessible.esm.mjs +3 -0
- package/lib/html2pdf-accessible.esm.mjs.LICENSE.txt +14 -0
- package/lib/html2pdf-accessible.esm.mjs.map +1 -0
- package/lib/html2pdf-accessible.js +3 -0
- package/lib/html2pdf-accessible.js.LICENSE.txt +14 -0
- package/lib/html2pdf-accessible.js.map +1 -0
- package/lib/html2pdf-accessible.min.js +17 -0
- package/lib/html2pdf-accessible.min.js.map +1 -0
- package/lib/types/core/bitwise.d.ts +1 -0
- package/lib/types/core/cache-storage.d.ts +27 -0
- package/lib/types/core/context.d.ts +17 -0
- package/lib/types/core/debugger.d.ts +8 -0
- package/lib/types/core/features.d.ts +12 -0
- package/lib/types/core/logger.d.ts +18 -0
- package/lib/types/core/util.d.ts +1 -0
- package/lib/types/css/IPropertyDescriptor.d.ts +36 -0
- package/lib/types/css/ITypeDescriptor.d.ts +6 -0
- package/lib/types/css/index.d.ts +134 -0
- package/lib/types/css/layout/bounds.d.ts +14 -0
- package/lib/types/css/layout/text.d.ts +13 -0
- package/lib/types/css/property-descriptors/background-clip.d.ts +8 -0
- package/lib/types/css/property-descriptors/background-color.d.ts +2 -0
- package/lib/types/css/property-descriptors/background-image.d.ts +3 -0
- package/lib/types/css/property-descriptors/background-origin.d.ts +8 -0
- package/lib/types/css/property-descriptors/background-position.d.ts +5 -0
- package/lib/types/css/property-descriptors/background-repeat.d.ts +9 -0
- package/lib/types/css/property-descriptors/background-size.d.ts +11 -0
- package/lib/types/css/property-descriptors/border-color.d.ts +5 -0
- package/lib/types/css/property-descriptors/border-radius.d.ts +7 -0
- package/lib/types/css/property-descriptors/border-style.d.ts +12 -0
- package/lib/types/css/property-descriptors/border-width.d.ts +5 -0
- package/lib/types/css/property-descriptors/box-shadow.d.ts +14 -0
- package/lib/types/css/property-descriptors/color.d.ts +2 -0
- package/lib/types/css/property-descriptors/content.d.ts +4 -0
- package/lib/types/css/property-descriptors/counter-increment.d.ts +7 -0
- package/lib/types/css/property-descriptors/counter-reset.d.ts +7 -0
- package/lib/types/css/property-descriptors/direction.d.ts +6 -0
- package/lib/types/css/property-descriptors/display.d.ts +35 -0
- package/lib/types/css/property-descriptors/duration.d.ts +2 -0
- package/lib/types/css/property-descriptors/float.d.ts +9 -0
- package/lib/types/css/property-descriptors/font-family.d.ts +4 -0
- package/lib/types/css/property-descriptors/font-size.d.ts +2 -0
- package/lib/types/css/property-descriptors/font-style.d.ts +7 -0
- package/lib/types/css/property-descriptors/font-variant.d.ts +2 -0
- package/lib/types/css/property-descriptors/font-weight.d.ts +2 -0
- package/lib/types/css/property-descriptors/letter-spacing.d.ts +2 -0
- package/lib/types/css/property-descriptors/line-break.d.ts +6 -0
- package/lib/types/css/property-descriptors/line-height.d.ts +4 -0
- package/lib/types/css/property-descriptors/list-style-image.d.ts +3 -0
- package/lib/types/css/property-descriptors/list-style-position.d.ts +6 -0
- package/lib/types/css/property-descriptors/list-style-type.d.ts +58 -0
- package/lib/types/css/property-descriptors/margin.d.ts +5 -0
- package/lib/types/css/property-descriptors/object-fit.d.ts +10 -0
- package/lib/types/css/property-descriptors/opacity.d.ts +2 -0
- package/lib/types/css/property-descriptors/overflow-wrap.d.ts +6 -0
- package/lib/types/css/property-descriptors/overflow.d.ts +9 -0
- package/lib/types/css/property-descriptors/padding.d.ts +5 -0
- package/lib/types/css/property-descriptors/paint-order.d.ts +8 -0
- package/lib/types/css/property-descriptors/position.d.ts +9 -0
- package/lib/types/css/property-descriptors/quotes.d.ts +8 -0
- package/lib/types/css/property-descriptors/text-align.d.ts +7 -0
- package/lib/types/css/property-descriptors/text-decoration-color.d.ts +2 -0
- package/lib/types/css/property-descriptors/text-decoration-line.d.ts +10 -0
- package/lib/types/css/property-descriptors/text-shadow.d.ts +12 -0
- package/lib/types/css/property-descriptors/text-transform.d.ts +8 -0
- package/lib/types/css/property-descriptors/transform-origin.d.ts +4 -0
- package/lib/types/css/property-descriptors/transform.d.ts +4 -0
- package/lib/types/css/property-descriptors/visibility.d.ts +7 -0
- package/lib/types/css/property-descriptors/webkit-text-stroke-color.d.ts +2 -0
- package/lib/types/css/property-descriptors/webkit-text-stroke-width.d.ts +2 -0
- package/lib/types/css/property-descriptors/word-break.d.ts +7 -0
- package/lib/types/css/property-descriptors/z-index.d.ts +7 -0
- package/lib/types/css/syntax/parser.d.ts +34 -0
- package/lib/types/css/syntax/tokenizer.d.ts +94 -0
- package/lib/types/css/types/angle.d.ts +7 -0
- package/lib/types/css/types/color-calculation.d.ts +3 -0
- package/lib/types/css/types/color-spaces/a98.d.ts +39 -0
- package/lib/types/css/types/color-spaces/p3.d.ts +45 -0
- package/lib/types/css/types/color-spaces/pro-photo.d.ts +45 -0
- package/lib/types/css/types/color-spaces/rec2020.d.ts +45 -0
- package/lib/types/css/types/color-spaces/srgb.d.ts +38 -0
- package/lib/types/css/types/color-utilities.d.ts +108 -0
- package/lib/types/css/types/color.d.ts +8 -0
- package/lib/types/css/types/functions/-prefix-linear-gradient.d.ts +4 -0
- package/lib/types/css/types/functions/-prefix-radial-gradient.d.ts +4 -0
- package/lib/types/css/types/functions/-webkit-gradient.d.ts +4 -0
- package/lib/types/css/types/functions/counter.d.ts +10 -0
- package/lib/types/css/types/functions/gradient.d.ts +7 -0
- package/lib/types/css/types/functions/linear-gradient.d.ts +4 -0
- package/lib/types/css/types/functions/radial-gradient.d.ts +12 -0
- package/lib/types/css/types/image.d.ts +54 -0
- package/lib/types/css/types/index.d.ts +1 -0
- package/lib/types/css/types/length-percentage.d.ts +11 -0
- package/lib/types/css/types/length.d.ts +4 -0
- package/lib/types/css/types/time.d.ts +2 -0
- package/lib/types/dom/document-cloner.d.ts +45 -0
- package/lib/types/dom/element-container.d.ts +20 -0
- package/lib/types/dom/elements/li-element-container.d.ts +6 -0
- package/lib/types/dom/elements/ol-element-container.d.ts +7 -0
- package/lib/types/dom/elements/select-element-container.d.ts +6 -0
- package/lib/types/dom/elements/textarea-element-container.d.ts +6 -0
- package/lib/types/dom/node-parser.d.ts +25 -0
- package/lib/types/dom/replaced-elements/canvas-element-container.d.ts +8 -0
- package/lib/types/dom/replaced-elements/iframe-element-container.d.ts +11 -0
- package/lib/types/dom/replaced-elements/image-element-container.d.ts +8 -0
- package/lib/types/dom/replaced-elements/index.d.ts +4 -0
- package/lib/types/dom/replaced-elements/input-element-container.d.ts +12 -0
- package/lib/types/dom/replaced-elements/pseudo-elements.d.ts +0 -0
- package/lib/types/dom/replaced-elements/svg-element-container.d.ts +8 -0
- package/lib/types/dom/text-container.d.ts +8 -0
- package/lib/types/fonts/font-collection.d.ts +25 -0
- package/lib/types/fonts/font-enumeration.d.ts +5 -0
- package/lib/types/fonts/font-style-mapping.d.ts +3 -0
- package/lib/types/fonts/interfaces.d.ts +27 -0
- package/lib/types/html2canvas.d.ts +10 -0
- package/lib/types/index.d.ts +7 -0
- package/lib/types/invariant.d.ts +1 -0
- package/lib/types/pdf/bookmarks.d.ts +4 -0
- package/lib/types/pdf/canvaskit-loader.d.ts +56 -0
- package/lib/types/pdf/document-structure.d.ts +105 -0
- package/lib/types/pdf/dom-updates.d.ts +6 -0
- package/lib/types/pdf/finalize-structure.d.ts +6 -0
- package/lib/types/pdf/hidden-captions.d.ts +15 -0
- package/lib/types/pdf/html-page-break.d.ts +11 -0
- package/lib/types/pdf/link-annotations.d.ts +8 -0
- package/lib/types/pdf/link-uri.d.ts +2 -0
- package/lib/types/pdf/logical-structure.d.ts +3 -0
- package/lib/types/pdf/pdf-export.d.ts +29 -0
- package/lib/types/pdf/single-html-multi-page.d.ts +14 -0
- package/lib/types/pdf/table-headers.d.ts +6 -0
- package/lib/types/pdf/xmp-metadata.d.ts +5 -0
- package/lib/types/render/background.d.ts +16 -0
- package/lib/types/render/bezier-curve.d.ts +14 -0
- package/lib/types/render/border.d.ts +6 -0
- package/lib/types/render/bound-curves.d.ts +32 -0
- package/lib/types/render/box-sizing.d.ts +4 -0
- package/lib/types/render/canvas/canvas-renderer.d.ts +53 -0
- package/lib/types/render/canvas/foreignobject-renderer.d.ts +11 -0
- package/lib/types/render/effects.d.ts +38 -0
- package/lib/types/render/font-metrics.d.ts +11 -0
- package/lib/types/render/path.d.ts +13 -0
- package/lib/types/render/renderer.d.ts +7 -0
- package/lib/types/render/skia/skia-font.d.ts +27 -0
- package/lib/types/render/skia/skia-renderer.d.ts +69 -0
- package/lib/types/render/stacking-context.d.ts +24 -0
- package/lib/types/render/vector.d.ts +9 -0
- package/lib/wasm/canvaskit-pdf.wasm +0 -0
- package/node_modules/@html2pdf-skia/canvaskit-pdf/CHROMIUM-LICENSE +27 -0
- package/node_modules/@html2pdf-skia/canvaskit-pdf/LICENSE +29 -0
- package/node_modules/@html2pdf-skia/canvaskit-pdf/README.md +35 -0
- package/node_modules/@html2pdf-skia/canvaskit-pdf/THIRD_PARTY_LICENSES.txt +2152 -0
- package/node_modules/@html2pdf-skia/canvaskit-pdf/bin/canvaskit.js +215 -0
- package/node_modules/@html2pdf-skia/canvaskit-pdf/chromium-license-source.json +5 -0
- package/node_modules/@html2pdf-skia/canvaskit-pdf/package.json +22 -0
- package/node_modules/@html2pdf-skia/canvaskit-pdf/pdf_bindings.cpp +179 -0
- package/node_modules/@html2pdf-skia/canvaskit-pdf/provenance.json +37 -0
- package/node_modules/@html2pdf-skia/canvaskit-pdf/types/google-types.d.ts +4948 -0
- package/node_modules/@html2pdf-skia/canvaskit-pdf/types/index.d.ts +48 -0
- package/node_modules/@webgpu/types/LICENSE +26 -0
- package/node_modules/@webgpu/types/README.md +132 -0
- package/node_modules/@webgpu/types/dist/index.d.ts +3426 -0
- package/node_modules/@webgpu/types/package.json +23 -0
- package/package.json +125 -4
- package/scripts/canvaskit/build.cjs +74 -0
- package/scripts/canvaskit/build.py +143 -0
- package/scripts/canvaskit/verify.cjs +82 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 pushpagarwal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,220 @@
|
|
|
1
|
-
#
|
|
1
|
+
# html2pdf-accessible
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Create accessible, searchable, and structured PDFs from HTML in the browser.
|
|
4
|
+
The renderer uses Skia / CanvasKit WASM for vector graphics and text, then adds PDF structure,
|
|
5
|
+
metadata and links. It is a fork of [html2pdf-skia](https://github.com/pushpagarwal/html2pdf-skia), which is based on html2canvas.
|
|
6
|
+
|
|
7
|
+
### Why this fork exists
|
|
8
|
+
|
|
9
|
+
html2pdf-skia already produced vector PDFs with selectable text and basic PDF
|
|
10
|
+
tagging. We needed more reliable structure for documents with tables, figures,
|
|
11
|
+
links and multiple pages. In particular, the upstream output did not provide
|
|
12
|
+
the table header associations and complete PDF structure relationships our
|
|
13
|
+
documents needed for navigation and validation.
|
|
14
|
+
|
|
15
|
+
This fork adds table header IDs and associations, caption handling, figure
|
|
16
|
+
bounds, link annotations, document metadata and outlines. It also finalizes PDF
|
|
17
|
+
structure after rendering, restores visually hidden captions as searchable text,
|
|
18
|
+
and adds browser, PDF and validator regression checks. The CanvasKit backend is
|
|
19
|
+
built from pinned source so the shipped WASM can be reproduced and audited.
|
|
20
|
+
These changes improve the generated PDF's accessibility, but each document
|
|
21
|
+
still needs validation and assistive-technology testing.
|
|
22
|
+
|
|
23
|
+
## Using the library
|
|
24
|
+
|
|
25
|
+
### 1. Install
|
|
26
|
+
|
|
27
|
+
With Node 22 or newer, install the package in your application:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npm install html2pdf-accessible
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2. Serve the WASM file and a font
|
|
34
|
+
|
|
35
|
+
Copy `node_modules/html2pdf-accessible/lib/wasm/canvaskit-pdf.wasm` from the
|
|
36
|
+
consuming project to a public URL such as `/assets/canvaskit-pdf.wasm`. Also
|
|
37
|
+
serve a font you are licensed to use, for example at `/fonts/YourFont-Regular.ttf`.
|
|
38
|
+
The PDF renderer needs the font bytes in addition to any CSS `@font-face` rule.
|
|
39
|
+
|
|
40
|
+
### 3. Export a document
|
|
41
|
+
|
|
42
|
+
Call this code in a browser after the document is ready:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import {
|
|
46
|
+
loadCanvasKit,
|
|
47
|
+
createFontCollection,
|
|
48
|
+
exportHTMLDocumentToPdf,
|
|
49
|
+
} from "html2pdf-accessible";
|
|
50
|
+
|
|
51
|
+
const kit = await loadCanvasKit({
|
|
52
|
+
wasmBinaryUrl: "/assets/canvaskit-pdf.wasm",
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const fonts = createFontCollection(kit);
|
|
56
|
+
const fontResponse = await fetch("/fonts/YourFont-Regular.ttf");
|
|
57
|
+
if (!fontResponse.ok) throw new Error("Could not load the PDF font");
|
|
58
|
+
fonts.addFont(await fontResponse.arrayBuffer(), "Your Font", {
|
|
59
|
+
fontWeight: 400,
|
|
60
|
+
});
|
|
61
|
+
fonts.setDefaultFonts("sans-serif", ["Your Font"]);
|
|
62
|
+
|
|
63
|
+
const pdf = await exportHTMLDocumentToPdf(kit, document, {
|
|
64
|
+
title: document.title,
|
|
65
|
+
language: document.documentElement.lang || "en-US",
|
|
66
|
+
pageSize: { width: 595, height: 842 },
|
|
67
|
+
userToPdfScale: 0.75,
|
|
68
|
+
fontCollection: fonts,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const url = URL.createObjectURL(pdf);
|
|
72
|
+
const link = document.createElement("a");
|
|
73
|
+
link.href = url;
|
|
74
|
+
link.download = "document.pdf";
|
|
75
|
+
link.click();
|
|
76
|
+
setTimeout(() => URL.revokeObjectURL(url), 30_000);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`exportHTMLDocumentToPdf` returns a PDF `Blob` and exports the supplied
|
|
80
|
+
`Document`'s body. If your page has buttons or navigation that should stay out
|
|
81
|
+
of the PDF, render the content in an iframe and pass its `contentDocument`
|
|
82
|
+
instead. Wait for its fonts and images to load before exporting. Page sizes use
|
|
83
|
+
PDF points; 595 × 842 is approximately A4. `userToPdfScale` converts CSS pixels
|
|
84
|
+
to PDF points; the default is `0.5`, while the example uses `0.75`. Register
|
|
85
|
+
additional font weights when your content uses them.
|
|
86
|
+
|
|
87
|
+
### Accessibility and limitations
|
|
88
|
+
|
|
89
|
+
Output has searchable text and a logical structure tree. Tests cover table
|
|
90
|
+
header IDs, category headers with colspan, repeated headers, multiple pages,
|
|
91
|
+
figures with alternative text/bounds, link annotations, XMP, outlines, hidden
|
|
92
|
+
captions and line wrapping. HTML must provide meaningful semantics, image
|
|
93
|
+
alternatives, document language and title.
|
|
94
|
+
|
|
95
|
+
Mark decorative `<img>` elements with `alt=""` and decorative inline `<svg>`
|
|
96
|
+
elements with `aria-hidden="true"` or `role="presentation"`. Give meaningful
|
|
97
|
+
images a non-empty `alt` and meaningful inline SVGs an `aria-label`.
|
|
98
|
+
|
|
99
|
+
Google SkPDF lacks some PDF structure operations. A final
|
|
100
|
+
pdf-lib pass adds the corresponding structure and annotations. Visually clipped
|
|
101
|
+
plain-text captions are restored as invisible embedded-font text. Custom font
|
|
102
|
+
collections must implement optional `getFontData(families, weight)` for these
|
|
103
|
+
captions; the supplied collection already implements it.
|
|
104
|
+
|
|
105
|
+
Passing veraPDF checks does **not** establish full PDF/UA or WCAG conformance for
|
|
106
|
+
every document. Reading order, descriptions and actual screen-reader table
|
|
107
|
+
navigation need manual testing. CSS support is limited by the DOM renderer;
|
|
108
|
+
browser layout remains the reference for supported content.
|
|
109
|
+
|
|
110
|
+
### Link and CSS safety
|
|
111
|
+
|
|
112
|
+
External PDF links allow only `https:` and `http:`. Relative web URLs are resolved
|
|
113
|
+
against the document base URL. Internal fragment links become PDF page destinations.
|
|
114
|
+
Other schemes, including `javascript:`, `data:`, `file:` and `mailto:`, remain
|
|
115
|
+
visible text without an active PDF link. URI policy is enforced at tag generation
|
|
116
|
+
and annotation serialization.
|
|
117
|
+
|
|
118
|
+
Relative color `calc()` expressions are evaluated as numbers, channel references,
|
|
119
|
+
parentheses and `+`, `-`, `*`, `/` operators. Unknown tokens, functions,
|
|
120
|
+
non-finite results and excessive nesting are rejected; CSS is never evaluated
|
|
121
|
+
as JavaScript. This does not make the library an HTML sanitizer.
|
|
122
|
+
|
|
123
|
+
### License
|
|
124
|
+
|
|
125
|
+
MIT; see [LICENSE](LICENSE) and [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
|
|
126
|
+
|
|
127
|
+
## Development guide
|
|
128
|
+
|
|
129
|
+
### Build from source
|
|
130
|
+
|
|
131
|
+
Use Node 22 or newer. Build this checkout and create a tarball for local testing:
|
|
132
|
+
|
|
133
|
+
```sh
|
|
134
|
+
npm ci
|
|
135
|
+
npm run build
|
|
136
|
+
npm pack
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
To test the archive in another project, install the tarball path printed by
|
|
140
|
+
`npm pack`. This repository does not publish to npm automatically.
|
|
141
|
+
|
|
142
|
+
### Tests
|
|
143
|
+
|
|
144
|
+
Install the project's Chromium browser once, then run the checks:
|
|
145
|
+
|
|
146
|
+
```sh
|
|
147
|
+
npm ci
|
|
148
|
+
npx playwright install chromium
|
|
149
|
+
npm test
|
|
150
|
+
npm run test:pdf
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The local Inter Regular and SemiBold test fonts are licensed under SIL Open Font
|
|
154
|
+
License 1.1; see `tests/pdf/assets/OFL.txt` in the source checkout. Test fonts,
|
|
155
|
+
fixtures, browsers and validator binaries are not included in the npm package.
|
|
156
|
+
Playwright, PDF.js, the native canvas adapter, fast-xml-parser and veraPDF are
|
|
157
|
+
development or CI tools, with their own licenses.
|
|
158
|
+
|
|
159
|
+
`npm test` runs all unit tests, validator-wrapper tests and TypeScript checking.
|
|
160
|
+
`test:pdf` builds the library, exports five synthetic fixtures in Chromium, and
|
|
161
|
+
checks structure and text with pdf-lib and PDF.js. Only local assets are used;
|
|
162
|
+
external requests fail. No Python, installed Edge, Java or veraPDF is required.
|
|
163
|
+
|
|
164
|
+
| Command | Purpose |
|
|
165
|
+
| --------------------------- | ------------------------------------------------------- |
|
|
166
|
+
| `npm run test:pdf:serve` | Interactive iframe runner on port 4001 |
|
|
167
|
+
| `npm run test:pdf:visual` | Compare pages with Linux reference images |
|
|
168
|
+
| `npm run test:pdf:update` | Explicitly replace references; review before committing |
|
|
169
|
+
| `npm run test:pdf:validate` | veraPDF PDF/UA-1 validation |
|
|
170
|
+
| `npm run test:package` | Pack, install, import and export using the npm tarball |
|
|
171
|
+
| `npm run lint:changed` | Check changed files with zero lint findings |
|
|
172
|
+
|
|
173
|
+
Results go to ignored `.cache/pdf-tests/`. Public tests, fixtures, assets and
|
|
174
|
+
reference images live under `tests/pdf/`; tools live under `scripts/pdf/`.
|
|
175
|
+
See [the test guide](tests/pdf/README.md) for the pinned Linux visual-test container,
|
|
176
|
+
manual release checks and lint policy. Windows/macOS developers use that container
|
|
177
|
+
for visual comparison and reference updates.
|
|
178
|
+
|
|
179
|
+
veraPDF uses Docker image `verapdf/cli:v1.30.2` by default. Alternatively set
|
|
180
|
+
`VERAPDF_PATH` to your local executable or Windows `verapdf.bat`. The wrapper
|
|
181
|
+
checks XML reports, completed jobs, parser errors and actual UA1 compliance;
|
|
182
|
+
exit status alone is insufficient. Missing tools/output fail instead of skipping.
|
|
183
|
+
|
|
184
|
+
GitHub Actions checks pull requests, main branches, release tags and manual runs,
|
|
185
|
+
including the actual packed library. PDFs, images and XML reports are artifacts.
|
|
186
|
+
The workflow checks release readiness and does not publish to npm.
|
|
187
|
+
|
|
188
|
+
### CanvasKit backend
|
|
189
|
+
|
|
190
|
+
The backend is built from [Google Skia CanvasKit](https://skia.googlesource.com/skia/+/e2def78fa232884d4aedcf3ad92d4a0dd673b898/modules/canvaskit/),
|
|
191
|
+
release 0.42.0, with our MIT-licensed C++ bridge to SkPDF. Official published
|
|
192
|
+
CanvasKit does not expose PDF generation; the bridge provides document creation,
|
|
193
|
+
page lifecycle, structure tags and stable font IDs. The existing public library
|
|
194
|
+
API and PDF layout are preserved.
|
|
195
|
+
|
|
196
|
+
Sources, licenses and provenance are under `deps/canvaskit-pdf/`. Every source
|
|
197
|
+
revision and the Emscripten build image are pinned. Normal installation uses the
|
|
198
|
+
included binaries; it does not download or compile Skia. Build hooks and tests
|
|
199
|
+
verify their hashes against the source manifest.
|
|
200
|
+
|
|
201
|
+
```sh
|
|
202
|
+
npm run verify:canvaskit
|
|
203
|
+
npm run build:canvaskit # Docker: rebuild and replace included artifacts
|
|
204
|
+
npm run test:canvaskit:rebuild # Docker: rebuild and compare, without replacing
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Only rebuilding requires Docker and network access to official source repositories.
|
|
208
|
+
Python and the C++ toolchain run inside the pinned build image. Build commands
|
|
209
|
+
use a Docker volume for source/dependency and compilation caches. CI rebuilds
|
|
210
|
+
from source in a fresh runner and requires the JavaScript, WASM, types, licenses
|
|
211
|
+
and provenance to match the included files. The build scripts are also shipped
|
|
212
|
+
in the npm package. See [backend details](deps/canvaskit-pdf/README.md).
|
|
213
|
+
|
|
214
|
+
### Contributions
|
|
215
|
+
|
|
216
|
+
Do not add production snapshots, customer data or proprietary assets to tests.
|
|
217
|
+
|
|
218
|
+
Pushes to `main` publish to npm only when the package version changes and all CI
|
|
219
|
+
checks pass. See the [publishing setup](https://github.com/MathiasCiarlo/html2pdf-accessible/blob/main/docs/publishing.md)
|
|
220
|
+
for versioning and npm Trusted Publishing configuration.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
This file identifies third-party code distributed with the npm package. The
|
|
4
|
+
project's own MIT license is in [LICENSE](LICENSE).
|
|
5
|
+
|
|
6
|
+
| Component | License | License text or attribution |
|
|
7
|
+
| --- | --- | --- |
|
|
8
|
+
| html2pdf-skia / html2canvas upstream code | MIT | [LICENSE](LICENSE); upstream attribution in [README.md](README.md) |
|
|
9
|
+
| Skia CanvasKit 0.42.0 and its native dependencies | BSD-3-Clause and component-specific licenses | [Skia license](deps/canvaskit-pdf/LICENSE), [native dependency notices](deps/canvaskit-pdf/THIRD_PARTY_LICENSES.txt), and [Chromium PartitionAlloc license](deps/canvaskit-pdf/CHROMIUM-LICENSE) |
|
|
10
|
+
| `@html2pdf-skia/canvaskit-pdf` PDF bridge (`pdf_bindings.cpp`) | MIT | [Bridge source](deps/canvaskit-pdf/pdf_bindings.cpp) and [project license](LICENSE) |
|
|
11
|
+
| `pdf-lib`, `@pdf-lib/fontkit`, `css-line-break`, `emoji-regex-xs`, `text-segmentation` | MIT | Their npm package metadata and license files where supplied; these libraries are bundled into `lib/` |
|
|
12
|
+
|
|
13
|
+
The CanvasKit source revision, build inputs, and artifact hashes are recorded in
|
|
14
|
+
[provenance.json](deps/canvaskit-pdf/provenance.json). The CanvasKit license files
|
|
15
|
+
above are included in the npm package alongside the JavaScript and WASM files.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Copyright 2015 The Chromium Authors
|
|
2
|
+
//
|
|
3
|
+
// Redistribution and use in source and binary forms, with or without
|
|
4
|
+
// modification, are permitted provided that the following conditions are
|
|
5
|
+
// met:
|
|
6
|
+
//
|
|
7
|
+
// * Redistributions of source code must retain the above copyright
|
|
8
|
+
// notice, this list of conditions and the following disclaimer.
|
|
9
|
+
// * Redistributions in binary form must reproduce the above
|
|
10
|
+
// copyright notice, this list of conditions and the following disclaimer
|
|
11
|
+
// in the documentation and/or other materials provided with the
|
|
12
|
+
// distribution.
|
|
13
|
+
// * Neither the name of Google LLC nor the names of its
|
|
14
|
+
// contributors may be used to endorse or promote products derived from
|
|
15
|
+
// this software without specific prior written permission.
|
|
16
|
+
//
|
|
17
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
18
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
19
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
20
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
21
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
22
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
23
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
24
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
25
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright (c) 2011 Google Inc. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Redistribution and use in source and binary forms, with or without
|
|
4
|
+
// modification, are permitted provided that the following conditions are
|
|
5
|
+
// met:
|
|
6
|
+
//
|
|
7
|
+
// * Redistributions of source code must retain the above copyright
|
|
8
|
+
// notice, this list of conditions and the following disclaimer.
|
|
9
|
+
// * Redistributions in binary form must reproduce the above
|
|
10
|
+
// copyright notice, this list of conditions and the following disclaimer
|
|
11
|
+
// in the documentation and/or other materials provided with the
|
|
12
|
+
// distribution.
|
|
13
|
+
// * Neither the name of Google Inc. nor the names of its
|
|
14
|
+
// contributors may be used to endorse or promote products derived from
|
|
15
|
+
// this software without specific prior written permission.
|
|
16
|
+
//
|
|
17
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
18
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
19
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
20
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
21
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
22
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
23
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
24
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
25
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
28
|
+
|
|
29
|
+
--------------------------------------------------------------------------------
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# CanvasKit PDF source build
|
|
2
|
+
|
|
3
|
+
This package uses Google's BSD-3-Clause Skia CanvasKit 0.42.0 from
|
|
4
|
+
https://skia.googlesource.com/skia.git at
|
|
5
|
+
`e2def78fa232884d4aedcf3ad92d4a0dd673b898`.
|
|
6
|
+
The only additional native implementation is `pdf_bindings.cpp` (MIT).
|
|
7
|
+
It calls SkPDF and exposes `MakePDFDocument`, `SetPDFTagId` and `GetTypefaceId`.
|
|
8
|
+
PDF structure names and numeric attributes are checked before serialization.
|
|
9
|
+
|
|
10
|
+
The builder enables SkPDF in Google's CanvasKit build, adds the bridge, and uses
|
|
11
|
+
CPU rendering, paragraph/font providers and client Unicode (plus SkPDF's
|
|
12
|
+
ICU bidi subset). GPU, Skottie,
|
|
13
|
+
embedded fonts, WOFF2 and tracing are disabled. Consumers supply fonts.
|
|
14
|
+
The upstream mutable Path API became PathBuilder; the library adapts this
|
|
15
|
+
internally without changing PDF export options. Direct CanvasKit consumers
|
|
16
|
+
receive Google's 0.42 API.
|
|
17
|
+
|
|
18
|
+
From the repository root, run `npm run build:canvaskit` to rebuild using Docker.
|
|
19
|
+
`npm run test:canvaskit:rebuild` compares the rebuilt artifacts without replacing
|
|
20
|
+
them. `scripts/canvaskit/build.py` runs inside the pinned Emscripten image;
|
|
21
|
+
Python is not a host requirement. `scripts/canvaskit/build.cjs` starts that image.
|
|
22
|
+
The build overlays two pinned Google build files; it rejects other source edits
|
|
23
|
+
and verifies all selected dependency checkouts against Google's DEPS revisions.
|
|
24
|
+
|
|
25
|
+
`provenance.json` records source and dependency revisions, compiler image digest,
|
|
26
|
+
bridge/build-script hashes and artifact hashes. Hashes alone do not prove trust:
|
|
27
|
+
CI additionally recompiles the source and compares the actual output.
|
|
28
|
+
`LICENSE`, `CHROMIUM-LICENSE` and `THIRD_PARTY_LICENSES.txt` cover upstream code.
|
|
29
|
+
PartitionAlloc's exported repository omits Chromium's root license; the pinned
|
|
30
|
+
primary source URL and digest of that license are recorded separately.
|
|
31
|
+
|
|
32
|
+
The bridge supplies SkPDF tags. The library still finalizes table header links,
|
|
33
|
+
figure bounds, annotation structure, metadata and outlines with pdf-lib.
|
|
34
|
+
Automated fixture results do not establish conformance for every document;
|
|
35
|
+
manual PAC and screen-reader testing remain release checks.
|