@zumer/snapdom-pdf 0.0.0-stage → 1.0.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # PDF changes
2
+
3
+ ## 1.0.1
4
+
5
+ > 9 November 2026
6
+
7
+ **Fixes**
8
+
9
+ - **pdf:** place the text layer correctly on hidpi screens [`05d87aa`](https://github.com/zumerlab/snapdom/commit/05d87aa81de0e03dd7c76e782626b629851b81ee)
10
+ - **pdf:** rasterize a capture enlarged to the paper at its printed size [`20add63`](https://github.com/zumerlab/snapdom/commit/20add63a27d31da61da1911001e1461ba4b7b99d)
11
+
12
+ **Refactoring**
13
+
14
+ - **pdf:** drop two locals nothing reads [`f49f5c1`](https://github.com/zumerlab/snapdom/commit/f49f5c1c050b83687d5a79365fca9ab4d280e4f4)
15
+
16
+ **Docs**
17
+
18
+ - **pdf:** rewrite the reference in plain words, capture the demo at dpr 2 [`b79e178`](https://github.com/zumerlab/snapdom/commit/b79e178f3f5fcd8b23c224ade730df830cf34d4a)
19
+ - **pdf:** fold the reference into the README [`e9f3a4f`](https://github.com/zumerlab/snapdom/commit/e9f3a4f8e0cde00e3a1bdab5f9ade5d06229346c)
20
+ - **site:** point the demos and docs at the published packages [`c57b2b3`](https://github.com/zumerlab/snapdom/commit/c57b2b38f3b57fc51e0cb7f64f8207ddad9421ef)
21
+
22
+ ## 1.0.0
23
+
24
+ > 9 November 2026
25
+
26
+ - First release as its own package, `@zumer/snapdom-pdf`. Up to `@zumer/snapdom-plugins` 4.4.1 the same exporter shipped at that package's `/pdf` subpath; its earlier history is in [packages/plugins/CHANGELOG.md](https://github.com/zumerlab/snapdom/blob/main/packages/plugins/CHANGELOG.md). Options and behavior are unchanged; only the import changes.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ZumerLab
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,226 @@
1
- # Temporary Holding Version
1
+ # @zumer/snapdom-pdf
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![NPM version](https://img.shields.io/npm/v/@zumer/snapdom-pdf?style=flat-square&label=PDF)](https://www.npmjs.com/package/@zumer/snapdom-pdf)
4
+ [![Core version](https://img.shields.io/npm/v/@zumer/snapdom?style=flat-square&label=SnapDOM)](https://www.npmjs.com/package/@zumer/snapdom)
5
+
6
+ PDF export for [SnapDOM](https://snapdom.dev/): `pdf()` adds `toPdf()` to a capture and turns it into a real PDF, with the capture's appearance, selectable and searchable text, links, bookmarks, pages, repeated table headers and fillable fields. Headers, footers, metadata, tagging and encryption are export options. Everything runs in the browser and nothing is uploaded. MIT licensed. Landing page and live demo: [snapdom.dev/plugins/pdf](https://snapdom.dev/plugins/pdf/).
7
+
8
+ ## Install
9
+
10
+ ```sh
11
+ npm install @zumer/snapdom@latest @zumer/snapdom-pdf@latest
12
+ ```
13
+
14
+ It needs SnapDOM 3.4.0 or newer within 3.x. Up to SnapDOM plugins 4.x the same exporter shipped as `@zumer/snapdom-plugins/pdf`; only the import changes.
15
+
16
+ Without a bundler, map both packages in an import map and serve the whole `@zumer/snapdom-pdf` folder, because its `index.js` imports files from `src/`.
17
+
18
+ ```html
19
+ <script type="importmap">
20
+ {
21
+ "imports": {
22
+ "@zumer/snapdom": "/vendor/snapdom.mjs",
23
+ "@zumer/snapdom-pdf": "/vendor/snapdom-pdf/index.js"
24
+ }
25
+ }
26
+ </script>
27
+ ```
28
+
29
+ ## Quick start
30
+
31
+ ```js
32
+ import { snapdom } from '@zumer/snapdom'
33
+ import { pdf } from '@zumer/snapdom-pdf'
34
+
35
+ snapdom.plugins(pdf())
36
+
37
+ const shot = await snapdom(document.querySelector('#report'))
38
+ const blob = await shot.toPdf({ page: 'a4', download: 'report.pdf' })
39
+ ```
40
+
41
+ Register the plugin before you capture. A capture made without it has no `toPdf()`. To use it on one capture only, pass it there: `snapdom(el, { plugins: [pdf()] })`.
42
+
43
+ `toPdf()` returns a PDF `Blob`. `download` also saves the file. `shot.to('pdf', options)` does the same as `toPdf(options)`. The types are in [index.d.ts](index.d.ts).
44
+
45
+ ## Options on pdf()
46
+
47
+ Five options decide what the plugin reads from the page while SnapDOM captures it, so they go on `pdf()` and not on `toPdf()`.
48
+
49
+ | Option | Default | What it does |
50
+ |---|---|---|
51
+ | `formValues` | `true` | Include the values typed in inputs and the selected option. Passwords become bullets. |
52
+ | `shadow` | `true` | Read text inside open shadow roots. |
53
+ | `breakAvoid` | `true` | Measure blocks so page breaks avoid cutting them. |
54
+ | `outline` | `true` | Turn headings into bookmarks. A selector string picks other elements; `false` turns it off. |
55
+ | `forms` | `true` | Measure form controls so the PDF can have fillable fields. |
56
+
57
+ Every other option works in either place. On `pdf()` it becomes the default for every export; in `toPdf()` it applies to that export and wins.
58
+
59
+ ## Pages
60
+
61
+ | Option | Default | What it does |
62
+ |---|---|---|
63
+ | `page` | `'fit'` | `'fit'` makes one page the size of the capture. Paper sizes: `'a3'` to `'a6'`, `'b4'`, `'b5'`, `'letter'`, `'legal'`, `'tabloid'`, `'executive'`, or `[width, height]` in points. |
64
+ | `orientation` | `'portrait'` | `'portrait'` or `'landscape'`. |
65
+ | `margin` | `24` | Margin on every side, in points. |
66
+ | `repeatHeaders` | `true` | Repeat a table's `<thead>` on each page the table continues to. |
67
+
68
+ Page breaks avoid table rows, list items, figures, quotes, images and anything with `break-inside: avoid`. CSS page breaks are respected. A block taller than a page still has to split.
69
+
70
+ ## Image and file size
71
+
72
+ What you see in the PDF is an image of the capture, with invisible text on top so it can be selected and searched.
73
+
74
+ | Option | Default | What it does |
75
+ |---|---|---|
76
+ | `image` | `true` | Draw the captured image. `false` makes a PDF with text only. |
77
+ | `codec` | `'auto'` | Try JPEG and lossless and keep the smaller file, per image. `'jpeg'` or `'flate'` forces one. |
78
+ | `quality` | `0.92` | JPEG quality. It only matters when JPEG wins, which on normal pages is rare. |
79
+ | `backgroundColor` | none | Fill transparent areas with a colour. Usually makes the file smaller. |
80
+
81
+ Sharpness and size come from the capture: `snapdom(el, { scale, dpr })`. Both multiply the image's pixels and leave the page layout alone. The image keeps that many pixels per CSS pixel at the size it is printed. A capture enlarged to fill the paper is drawn at the enlarged size, so it stays as sharp as on screen. `dpr` defaults to the screen of the machine that exports, so set it, for example to `2`, to get the same file everywhere.
82
+
83
+ ## Text and links
84
+
85
+ | Option | Default | What it does |
86
+ |---|---|---|
87
+ | `text` | `true` | Add the invisible text layer, so the text can be selected, searched and copied. |
88
+ | `links` | `true` | Make links clickable. Same-page anchors jump inside the PDF. |
89
+ | `debugText` | `false` | Paint the text layer red, to check where it sits. |
90
+
91
+ Links work for `http:`, `https:`, `mailto:` and `tel:`. Any other link is left out with a warning.
92
+
93
+ > Covering something with a box or a blur hides the pixels, not the text: it can still be selected in the PDF. To keep data out, remove or replace it before the capture.
94
+
95
+ ## Fonts and sharp text
96
+
97
+ | Option | Default | What it does |
98
+ |---|---|---|
99
+ | `embedFonts` | `true` | Embed the page's web fonts, only the letters the document uses. `'full'` embeds whole fonts; `false` none. |
100
+ | `vectorText` | `false` | Draw the text as real letters instead of pixels: sharp at any zoom. |
101
+
102
+ The PDF can only embed fonts the capture carries, so capture with `snapdom(el, { embedFonts: true })`. System fonts have no file to embed. Copying text works the same with or without embedded fonts.
103
+
104
+ `vectorText` needs embedded fonts. Right-to-left and complex scripts stay as image. With `image: false` it gives a very small text-only PDF, without borders, backgrounds or pictures.
105
+
106
+ ## Bookmarks and accessibility
107
+
108
+ | Option | Default | What it does |
109
+ |---|---|---|
110
+ | `outline` | `true` | Bookmarks from headings. Set it on `pdf()`. |
111
+ | `tagged` | `true` | Tag headings, paragraphs, lists, tables and figures for screen readers. |
112
+ | `lang` | from the page | Document language, for example `'en'` or `'es-MX'`. |
113
+
114
+ The PDF is marked accessible (PDF/UA-1) only when it qualifies: every font embedded, a language, a `meta.title`, alt text on every image and `fields: false`. There is no option to force it. When something is missing, the report says what.
115
+
116
+ ## Fillable forms
117
+
118
+ | Option | Default | What it does |
119
+ |---|---|---|
120
+ | `fields` | `true` | Turn form controls into fields you can fill in the PDF. `false` keeps their values as plain text. |
121
+
122
+ Text inputs, textareas, checkboxes, radio buttons and selects become fields with their name, value and label. Read-only, disabled, required and maxlength carry over. Password fields are written empty. Buttons, sliders, colour pickers and file inputs stay as image. The PDF never contains scripts or submit actions.
123
+
124
+ ## Header, footer and page numbers
125
+
126
+ | Option | Default | What it does |
127
+ |---|---|---|
128
+ | `header` | none | Text, a function, `{ left, center, right, size, font, color, rule, gap }` or an element. |
129
+ | `footer` | none | The same, at the bottom. |
130
+ | `pageNumbers` | `false` | `true` writes "1 / 4". `{ format, align, size, font, color }` changes it. |
131
+
132
+ ```js
133
+ await shot.toPdf({
134
+ page: 'a4',
135
+ header: { left: 'North Studio', right: 'Delivery report' },
136
+ pageNumbers: { format: (page, pages) => `Page ${page} of ${pages}` },
137
+ })
138
+ ```
139
+
140
+ These need a paper size and do nothing on `page: 'fit'`. Text is real PDF text. An element is captured as an image, so its text cannot be selected.
141
+
142
+ ## Cover, contents, back page and watermark
143
+
144
+ | Option | Default | What it does |
145
+ |---|---|---|
146
+ | `cover` | none | An element captured as the first page. |
147
+ | `toc` | none | A table of contents from the headings. `true`, a title, or `{ title, levels, size, font, indent, dots, label, color, leaderColor }`. |
148
+ | `back` | none | An element captured as the last page. |
149
+ | `watermark` | none | Text or an element over every page. `{ text, opacity, angle, size, font, color }` or `{ element, opacity, angle, fit }`. |
150
+
151
+ Cover, contents and back page need a paper size. The watermark also works on `page: 'fit'`.
152
+
153
+ ## Metadata
154
+
155
+ | Option | Default | What it does |
156
+ |---|---|---|
157
+ | `meta` | none | `{ title, author, subject, keywords, creator, created, modified }`. Viewers show the title instead of the file name. |
158
+
159
+ Dates are written only when you pass them. Pass `new Date()` when you want today. The same page exported twice gives the same file, byte for byte.
160
+
161
+ ## Password
162
+
163
+ ```js
164
+ await shot.toPdf({
165
+ page: 'a4',
166
+ encrypt: { userPassword: 'ada-1815', ownerPassword: 'owner-key' },
167
+ })
168
+ ```
169
+
170
+ `encrypt` protects the file with AES-256. `userPassword` is required. `ownerPassword` defaults to it. `permissions` takes `print`, `modify`, `copy`, `annotate`, `fillForms`, `assemble` and `printHighRes`, all `true` by default.
171
+
172
+ Only the password protects the file. Permissions are requests that a viewer may ignore. Encryption needs https or localhost, and an encrypted export is different every time.
173
+
174
+ ## Output
175
+
176
+ | Option | Default | What it does |
177
+ |---|---|---|
178
+ | `download` | `false` | A file name, or `true` for `snapdom.pdf`. The Blob is still returned. |
179
+ | `deflate` | `true` | Compress the PDF's internal streams. |
180
+
181
+ ## Progress, cancel and report
182
+
183
+ | Option | Default | What it does |
184
+ |---|---|---|
185
+ | `onProgress` | none | Called with `{ phase, done, total }` as pages are made. `total` is `null` until the page count is known. |
186
+ | `signal` | none | An `AbortSignal`. Aborting stops the export with an `AbortError`. |
187
+ | `onReport` | none | Called once the PDF is done, with what happened: pages, size, fields, fonts and warnings. |
188
+
189
+ ```js
190
+ await shot.toPdf({
191
+ page: 'a4',
192
+ onProgress: ({ done, total }) => bar.update(done, total),
193
+ signal: controller.signal,
194
+ onReport: (report) => console.log(report.pages, report.warnings),
195
+ })
196
+ ```
197
+
198
+ Each warning in the report has a `code`, such as `link-unresolved` or `text-clipped`, so a test can check for them without reading messages.
199
+
200
+ ## When something looks wrong
201
+
202
+ The plugin warns in the console with a `[snapdom-pdf]` prefix: a block split across pages, a link without a target, text cut off. The same warnings arrive in the report.
203
+
204
+ A grey box where an image should be means the capture could not read that image. It shows up in the capture's `result.warnings` as `image-fallback`. [Export a PDF with cross-origin images](https://snapdom.dev/how-to/pdf-cross-origin-images/) explains the fix.
205
+
206
+ If the PDF does not match the page, [open an issue](https://github.com/zumerlab/snapdom/issues) with a small example and we will fix it.
207
+
208
+ ## Limits
209
+
210
+ - Text is an image unless you use `vectorText`, so a deep zoom shows the capture's resolution.
211
+ - Closed shadow roots cannot be read.
212
+ - Date inputs are written in ISO format, not as the browser shows them.
213
+ - An element used as header, footer or watermark has no selectable text. A repeated table header has no links.
214
+ - The full test suite runs in Chromium. Firefox and WebKit are checked for the main features.
215
+
216
+ ## Migrating from `pdf-image`
217
+
218
+ Replace `pdfImage()` with `pdf()` and `toPdfImage()` with `toPdf({ download: 'capture.pdf' })`. Put orientation on the export. The old temporary object-URL return becomes a persistent Blob. The default page sizing and pagination differ: choose `page: 'a4'` explicitly.
219
+
220
+ ## Live demo and verification
221
+
222
+ From the monorepo root, run `npm run compile` and `npm run site`, then open `/plugins/pdf/` or `/showcase/`. The demos generate real PDFs from editable DOM samples. Run `npm run test:pdf` for the PDF engine suites; see the [verification notes](test/README.md).
223
+
224
+ ## License
225
+
226
+ MIT
package/index.d.ts ADDED
@@ -0,0 +1,294 @@
1
+ import type { SnapdomPlugin } from '@zumer/snapdom'
2
+
3
+ /** PDF page sizes supported by the exporter. Custom pairs are PDF points. */
4
+ export type PdfPageSize =
5
+ | 'fit'
6
+ | 'a3'
7
+ | 'a4'
8
+ | 'a5'
9
+ | 'a6'
10
+ | 'b4'
11
+ | 'b5'
12
+ | 'letter'
13
+ | 'legal'
14
+ | 'tabloid'
15
+ | 'executive'
16
+ | readonly [width: number, height: number]
17
+
18
+ export type PdfOrientation = 'portrait' | 'landscape'
19
+ export type PdfImageCodec = 'auto' | 'jpeg' | 'flate'
20
+ export type PdfBase14Family = 'sans' | 'serif' | 'mono'
21
+ /**
22
+ * Furniture type. `'document'`, the default, is the body's own embedded face,
23
+ * falling back to base-14 sans per string; the other three mean base-14.
24
+ */
25
+ export type PdfFontFamily = 'document' | PdfBase14Family
26
+ export type PdfTextValue = string | number | null | undefined
27
+ export type PdfPageText = PdfTextValue | ((page: number, pages: number) => PdfTextValue)
28
+
29
+ export interface PdfTextBand {
30
+ left?: PdfPageText
31
+ center?: PdfPageText
32
+ right?: PdfPageText
33
+ /** Font size in PDF points. Default 9. */
34
+ size?: number
35
+ font?: PdfFontFamily
36
+ /** Three- or six-digit hexadecimal colour. */
37
+ color?: string
38
+ /** Alias accepted by the runtime. */
39
+ colour?: string
40
+ /** Draw the separator rule. Default true. */
41
+ rule?: boolean
42
+ /** Space between the text and rule, in PDF points. Default 10. */
43
+ gap?: number
44
+ }
45
+
46
+ export type PdfBand = string | ((page: number, pages: number) => PdfTextValue) | PdfTextBand | Element | null
47
+
48
+ export interface PdfPageNumbers {
49
+ format?: (page: number, pages: number) => PdfTextValue
50
+ align?: 'left' | 'center' | 'right'
51
+ size?: number
52
+ font?: PdfFontFamily
53
+ color?: string
54
+ colour?: string
55
+ }
56
+
57
+ export interface PdfTableOfContents {
58
+ title?: string
59
+ /** Outline depths to include. Default 3. */
60
+ levels?: number
61
+ size?: number
62
+ font?: PdfFontFamily
63
+ indent?: number
64
+ dots?: boolean
65
+ /** Formats the body page number printed by the index. */
66
+ label?: (page: number, bodyPages: number) => PdfTextValue
67
+ color?: string
68
+ colour?: string
69
+ leaderColor?: string
70
+ leaderColour?: string
71
+ }
72
+
73
+ export interface PdfTextWatermark {
74
+ text: string
75
+ opacity?: number
76
+ angle?: number
77
+ /** Zero or omitted auto-fits the text to the page. */
78
+ size?: number
79
+ font?: PdfFontFamily
80
+ color?: string
81
+ colour?: string
82
+ }
83
+
84
+ export interface PdfElementWatermark {
85
+ element: Element
86
+ opacity?: number
87
+ angle?: number
88
+ /** Fraction of the page's limiting dimension. Default 0.6. */
89
+ fit?: number
90
+ }
91
+
92
+ export type PdfWatermark = string | Element | PdfTextWatermark | PdfElementWatermark | null
93
+
94
+ /** Document properties written to /Info and mirrored into the XMP packet. */
95
+ /**
96
+ * Permission flags. Every one defaults to true, and every one is ADVISORY: a
97
+ * viewer may honour it and any other tool may ignore it. Only `userPassword`
98
+ * protects anything. Extraction for accessibility is deliberately not offered:
99
+ * PDF 2.0 deprecates that bit and PDF/UA requires an encrypted file to keep
100
+ * permitting it.
101
+ */
102
+ export interface PdfPermissions {
103
+ print?: boolean
104
+ modify?: boolean
105
+ copy?: boolean
106
+ annotate?: boolean
107
+ fillForms?: boolean
108
+ assemble?: boolean
109
+ printHighRes?: boolean
110
+ }
111
+
112
+ export interface PdfEncryption {
113
+ /** Required, non-empty: without it the reader cannot open the file at all. */
114
+ userPassword: string
115
+ /** Lifts the permission flags. Defaults to the user password. */
116
+ ownerPassword?: string
117
+ permissions?: PdfPermissions
118
+ }
119
+
120
+ export interface PdfDocumentMeta {
121
+ title?: string
122
+ author?: string
123
+ subject?: string
124
+ keywords?: string | readonly string[]
125
+ /** The producing APPLICATION (xmp:CreatorTool); Producer is always snapdom-pdf. */
126
+ creator?: string
127
+ /**
128
+ * Written only when given: an invented "now" would break byte determinism.
129
+ * Pass new Date() yourself when you want it.
130
+ */
131
+ created?: Date | string
132
+ modified?: Date | string
133
+ }
134
+
135
+ export type PdfProgressPhase = 'measure' | 'page' | 'matter' | 'assemble'
136
+
137
+ export interface PdfProgress {
138
+ phase: PdfProgressPhase
139
+ /** Pages done in this phase, or null when the phase has no count. */
140
+ done: number | null
141
+ /** Body page total, or null before pagination knows it. */
142
+ total: number | null
143
+ }
144
+
145
+ /** One warning, carrying its stable machine-readable code. */
146
+ export interface PdfWarning {
147
+ code: string
148
+ message: string
149
+ }
150
+
151
+ /** One face whose font program travels in the document. */
152
+ export interface PdfEmbeddedFont {
153
+ /** The /BaseFont name; a subset carries the `AAAAAA+` tag PDF 9.6.4 asks for. */
154
+ name: string
155
+ /** The CSS-facing request this face answered, e.g. `"Inter" 700`. */
156
+ label: string
157
+ /** Size of the embedded program before stream compression. */
158
+ kB: number
159
+ /** true when only the used glyphs travel; false when the whole file does. */
160
+ subset: boolean
161
+ }
162
+
163
+ /** Everything gateable about a finished export. Identical exports produce identical reports. */
164
+ export interface PdfReport {
165
+ warnings: readonly PdfWarning[]
166
+ /** Warning tallies keyed by code. */
167
+ counts: Readonly<Record<string, number>>
168
+ pages: number
169
+ bytes: number
170
+ /** Fillable fields written. */
171
+ fields: number
172
+ /** Link and widget annotations written. */
173
+ annotations: number
174
+ /** Faces embedded from the capture's own @font-face rules, subset or whole. */
175
+ fontsEmbedded: readonly PdfEmbeddedFont[]
176
+ /**
177
+ * true when this export EARNED and wrote the PDF/UA-1 identifier: every
178
+ * text operation on an embedded face, tagged structure, a language, a
179
+ * displayed title, and no painted image without alternative text. Never
180
+ * configurable; the `ua-withheld` warning names the blockers when false.
181
+ */
182
+ pdfua: boolean
183
+ /** Text runs `vectorText` painted as real glyphs. 0 when it is off. */
184
+ vectorText: number
185
+ }
186
+
187
+ /** Options evaluated when a finished SnapDOM capture is exported. */
188
+ export interface PdfExportOptions {
189
+ page?: PdfPageSize
190
+ orientation?: PdfOrientation
191
+ /** Margin on all sides, in PDF points. Ignored by page: 'fit'. */
192
+ margin?: number
193
+ text?: boolean
194
+ links?: boolean
195
+ /**
196
+ * Draw raster/XObject content. false keeps enabled text, links and structure,
197
+ * but omits Element headers, footers and watermarks.
198
+ */
199
+ image?: boolean
200
+ /** Compress PDF content streams. Default true. */
201
+ deflate?: boolean
202
+ /** Quality of the JPEG candidate. Ignored when lossless Flate wins. */
203
+ quality?: number
204
+ codec?: PdfImageCodec
205
+ /** Flatten the capture onto this colour for this PDF export. */
206
+ backgroundColor?: string | null
207
+ header?: PdfBand
208
+ footer?: PdfBand
209
+ pageNumbers?: boolean | PdfPageNumbers
210
+ repeatHeaders?: boolean
211
+ /** Emit a PDF structure tree. Structure alone is not a PDF/UA-1 claim; see `PdfReport.pdfua`. */
212
+ tagged?: boolean
213
+ /** PDF document language, for example "en" or "es-MX". */
214
+ lang?: string | null
215
+ /**
216
+ * Embed the capture's @font-face binaries and point the text at them. `true`
217
+ * (default) subsets each face to the glyphs the document drew; `'full'`
218
+ * embeds whole files; `false` embeds nothing. Needs the capture to carry its
219
+ * fonts: snapdom's own `embedFonts: true` capture option.
220
+ */
221
+ embedFonts?: boolean | 'full'
222
+ /**
223
+ * Paint eligible text as real vector glyphs from the embedded fonts instead
224
+ * of leaving it invisible over the raster, crisp at any zoom. Only faithful
225
+ * where no shaping intervenes (left-to-right runs in an embedded face), so
226
+ * RTL and uncovered runs stay on the raster. Pair with `image: false` for a
227
+ * tiny, fully-vector text PDF; with `image: true` the glyphs overpaint the
228
+ * raster. Default false.
229
+ */
230
+ vectorText?: boolean
231
+ cover?: Element | null
232
+ back?: Element | null
233
+ toc?: boolean | string | PdfTableOfContents | null
234
+ watermark?: PdfWatermark
235
+ debugText?: boolean
236
+ /** A filename, or true for "snapdom.pdf". The Blob is always returned. */
237
+ download?: boolean | string
238
+ /**
239
+ * Emit measured form controls as fillable AcroForm fields. Default true.
240
+ * false keeps their values in the invisible text layer instead.
241
+ */
242
+ fields?: boolean
243
+ /** Document properties: /Info, XMP, and DisplayDocTitle when title is set. */
244
+ meta?: PdfDocumentMeta | null
245
+ /**
246
+ * Encrypt the file with AES-256 (standard security handler, revision 6), so
247
+ * the download itself is protected at rest. `userPassword` is required: a PDF
248
+ * with an empty one is encrypted and still opens without asking.
249
+ */
250
+ encrypt?: PdfEncryption | null
251
+ /** Abort the export between pages. Rejects with the signal's AbortError. */
252
+ signal?: AbortSignal
253
+ /** Progress narration; a throwing callback is dropped, never fatal. */
254
+ onProgress?: (progress: PdfProgress) => void
255
+ /** Receives the structured diagnostics report after the Blob is finished. */
256
+ onReport?: (report: PdfReport) => void
257
+
258
+ /** @deprecated Capture resolution belongs to snapdom(...), not toPdf(...). */
259
+ scale?: never
260
+ /** @deprecated Use deflate for PDF streams; SnapDOM owns compress. */
261
+ compress?: never
262
+ /** @deprecated Use download; SnapDOM owns filename. */
263
+ filename?: never
264
+ /** @deprecated Use backgroundColor. */
265
+ background?: never
266
+ }
267
+
268
+ /**
269
+ * Defaults accepted by pdf(). The first five options are capture-time and cannot
270
+ * be changed by a later toPdf() call. Every PdfExportOptions field may also be a
271
+ * factory default and can then be overridden by toPdf().
272
+ */
273
+ export interface PdfPluginOptions extends PdfExportOptions {
274
+ formValues?: boolean
275
+ shadow?: boolean
276
+ breakAvoid?: boolean
277
+ /** true for h1-h6/role=heading, a selector string, or false. */
278
+ outline?: boolean | string
279
+ /** Measure form controls for fillable fields. Default true. Capture-time. */
280
+ forms?: boolean
281
+ }
282
+
283
+ /** Create a PDF plugin for @zumer/snapdom >=3.0.0 <4. */
284
+ declare function pdf(defaults?: PdfPluginOptions): SnapdomPlugin
285
+
286
+ export { pdf }
287
+ export default pdf
288
+
289
+ declare module '@zumer/snapdom' {
290
+ interface CaptureResult {
291
+ /** Export this already-created capture as a PDF Blob. */
292
+ toPdf(options?: PdfExportOptions): Promise<Blob>
293
+ }
294
+ }
package/index.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @zumer/snapdom-pdf
3
+ * PDF export for SnapDOM: `pdf()` adds `result.toPdf()`.
4
+ *
5
+ * import { pdf } from '@zumer/snapdom-pdf'
6
+ *
7
+ * Up to @zumer/snapdom-plugins 4.x the same exporter shipped at that package's `/pdf` subpath.
8
+ */
9
+ export { default, pdf } from './src/index.js'
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "@zumer/snapdom-pdf",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.1",
4
+ "description": "PDF export for SnapDOM: searchable, paginated documents with selectable text, links and optional form fields",
5
+ "type": "module",
6
+ "scripts": {
7
+ "bump:dry": "npx @zumerbox/bump -d",
8
+ "bump": "npx @zumerbox/bump && npx @zumerbox/changelog"
9
+ },
10
+ "exports": {
11
+ ".": "./index.js"
12
+ },
13
+ "types": "./index.d.ts",
14
+ "files": [
15
+ "index.js",
16
+ "index.d.ts",
17
+ "src/",
18
+ "README.md",
19
+ "CHANGELOG.md"
20
+ ],
21
+ "keywords": [
22
+ "snapdom",
23
+ "snapdom-plugin",
24
+ "dom-capture",
25
+ "pdf",
26
+ "html-to-pdf"
27
+ ],
28
+ "author": "Juan Martin Muda",
29
+ "license": "MIT",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/zumerlab/snapdom.git",
33
+ "directory": "packages/pdf"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/zumerlab/snapdom/issues"
37
+ },
38
+ "homepage": "https://snapdom.dev/plugins/pdf/",
39
+ "funding": {
40
+ "type": "github",
41
+ "url": "https://github.com/sponsors/tinchox5"
42
+ },
43
+ "peerDependencies": {
44
+ "@zumer/snapdom": "^3.4.0"
45
+ },
46
+ "devDependencies": {
47
+ "@zumer/snapdom": "file:../.."
48
+ },
49
+ "sideEffects": false
50
+ }