@imggion/html2realpdf 0.1.14-rc1 → 0.1.14

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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imggion/html2realpdf",
3
- "version": "0.1.14-rc1",
3
+ "version": "0.1.14",
4
4
  "description": "Browser-first HTML to real, selectable PDF rendering powered by Zig and WebAssembly",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: html2realpdf
3
- description: Integrate and troubleshoot @imggion/html2realpdf in browser TypeScript or JavaScript projects. Use when rendering HTML strings, DOM elements, or React-compatible refs to selectable PDFs; configuring pages, resources, fonts, SVG or canvas output; previewing, downloading, or exporting PDFs; inspecting diagnostics; or migrating supported html2pdf.js chains.
3
+ description: Integrate and troubleshoot @imggion/html2realpdf in browser TypeScript or JavaScript projects. Use when rendering HTML strings, DOM elements, or React-compatible refs to selectable PDFs; designing production HTML and CSS templates; configuring deterministic A4 layouts, pagination, cards, tables, legends, resources, fonts, SVG, or canvas output; diagnosing clipped content, blank pages, or alignment issues; previewing, downloading, or exporting PDFs; inspecting diagnostics; or migrating supported html2pdf.js chains.
4
4
  ---
5
5
 
6
6
  # Use html2realpdf
@@ -45,6 +45,240 @@ try {
45
45
  Treat four-value margins as `[top, left, bottom, right]`, matching the
46
46
  html2pdf.js compatibility API rather than CSS shorthand order.
47
47
 
48
+ ## Author production report templates
49
+
50
+ Define one page geometry contract. Prefer `page.margin` for application-owned
51
+ reports, then size the rendered root against the resulting content box. Do not
52
+ also add equivalent `@page` margins and root padding.
53
+
54
+ ```ts
55
+ import { renderPdf, type RenderOptions } from "@imggion/html2realpdf";
56
+ const reportOptions: RenderOptions = {
57
+ page: { format: "a4", unit: "mm", margin: [12, 13, 12, 13] },
58
+ cssProfile: "web",
59
+ mediaType: "print",
60
+ layoutContext: "page",
61
+ viewport: { width: 1200, height: 1600 },
62
+ pageBreak: { avoid: [".pdf-atomic"], legacy: false },
63
+ fallback: "error",
64
+ };
65
+ const pdf = await renderPdf(document.querySelector("#report")!, reportOptions);
66
+ ```
67
+
68
+ For A4 with 13 mm left and right margins, the content box is 184 mm wide. A
69
+ root width of `100%` is usually sufficient; use the explicit maximum only when
70
+ the template must remain independent of its host page.
71
+
72
+ ```html
73
+ <main id="report" class="pdf-document">
74
+ <header class="pdf-header">
75
+ <img class="pdf-logo" src="/brand/logo.svg" alt="Example Company" />
76
+ <div><p class="pdf-eyebrow">Assessment report</p><h1>Candidate name</h1></div>
77
+ </header>
78
+ <section class="pdf-section">
79
+ <h2 class="pdf-keep-with-next">Profile</h2>
80
+ <dl class="pdf-metadata-grid">
81
+ <div><dt>Role</dt><dd>Product Designer</dd></div>
82
+ <div><dt>Interview date</dt><dd>28 July 2026</dd></div>
83
+ </dl>
84
+ </section>
85
+ <section class="pdf-section">
86
+ <h2 class="pdf-keep-with-next">Summary</h2>
87
+ <article class="pdf-card pdf-atomic">
88
+ <h3>Key finding</h3>
89
+ <p>Keep short, related content together inside a bounded card.</p>
90
+ </article>
91
+ </section>
92
+ </main>
93
+ ```
94
+
95
+ ```css
96
+ @media print {
97
+ .pdf-document, .pdf-document * { box-sizing: border-box; }
98
+ .pdf-document {
99
+ width: 100%;
100
+ max-width: 184mm;
101
+ margin: 0 auto;
102
+ color: #172033;
103
+ background: #fff;
104
+ font-family: Inter, Arial, sans-serif;
105
+ font-size: 10pt;
106
+ line-height: 1.45;
107
+ }
108
+ .pdf-header {
109
+ display: flex;
110
+ align-items: center;
111
+ gap: 8mm;
112
+ padding-bottom: 6mm;
113
+ border-bottom: 0.3mm solid #d8dee9;
114
+ }
115
+ .pdf-logo { display: block; width: 30mm; height: auto; }
116
+ .pdf-section { margin-top: 8mm; }
117
+ .pdf-section > :first-child { margin-top: 0; }
118
+ .pdf-section > :last-child { margin-bottom: 0; }
119
+ .pdf-metadata-grid {
120
+ display: grid;
121
+ grid-template-columns: repeat(2, minmax(0, 1fr));
122
+ gap: 4mm 8mm;
123
+ margin: 0;
124
+ }
125
+ .pdf-metadata-grid > div { min-width: 0; }
126
+ .pdf-metadata-grid dt { color: #667085; font-size: 8.5pt; }
127
+ .pdf-metadata-grid dd { margin: 1mm 0 0; overflow-wrap: anywhere; }
128
+ }
129
+ ```
130
+
131
+ Use a mounted `Element` rather than an HTML string when the template depends
132
+ on computed styles, pseudo-elements, responsive rules, live form values, or
133
+ canvas state.
134
+
135
+ ### Compose pagination deliberately
136
+
137
+ Use a small set of named pagination primitives instead of applying avoidance
138
+ to every container.
139
+
140
+ ```css
141
+ .pdf-flow { break-inside: auto; page-break-inside: auto; }
142
+ .pdf-atomic { break-inside: avoid; page-break-inside: avoid; }
143
+ .pdf-keep-with-next { break-after: avoid; page-break-after: avoid; }
144
+ .pdf-break-before { break-before: page; page-break-before: always; }
145
+ ```
146
+
147
+ - Apply `.pdf-atomic` only to content known to fit on one page. Let long prose,
148
+ lists, and tables fragment normally.
149
+ - Keep a heading with the following block, but do not combine adjacent
150
+ `break-after` and `break-before` rules for the same boundary.
151
+ - Prefer authored CSS plus narrow `pageBreak.avoid` selectors. Do not use
152
+ `avoidAll: true` or broad selectors such as every `div` in production.
153
+ - Use one explicit page-break strategy. Do not insert empty spacer elements or
154
+ mutate the DOM after measuring page positions.
155
+
156
+ ### Keep cards intact
157
+
158
+ Use semantic, bounded cards and give every painted surface an explicit
159
+ background.
160
+
161
+ ```css
162
+ .pdf-card {
163
+ padding: 5mm;
164
+ border: 0.3mm solid #d8dee9;
165
+ border-radius: 3mm;
166
+ background-color: #fff;
167
+ }
168
+ .pdf-card > :first-child { margin-top: 0; }
169
+ .pdf-card > :last-child { margin-bottom: 0; }
170
+ ```
171
+
172
+ If a card can grow beyond one page, remove `.pdf-atomic`, allow the content to
173
+ flow, and avoid clipping overflow on its wrapper.
174
+
175
+ ### Render tables predictably
176
+
177
+ Use semantic tables, declare column tracks explicitly, and keep cell widths
178
+ consistent across every row.
179
+
180
+ ```html
181
+ <div class="pdf-table-frame">
182
+ <table class="pdf-table">
183
+ <colgroup><col class="pdf-col-label" /><col /><col class="pdf-col-indicator" /></colgroup>
184
+ <thead><tr><th>Competency</th><th>Evidence</th><th>Level</th></tr></thead>
185
+ <tbody>
186
+ <tr>
187
+ <th scope="row">Collaboration</th>
188
+ <td>Concise evidence that may wrap onto multiple lines.</td>
189
+ <td class="pdf-indicator-cell">
190
+ <span class="pdf-level"><span class="pdf-dot pdf-dot-good"></span>High</span>
191
+ </td>
192
+ </tr>
193
+ </tbody>
194
+ </table>
195
+ </div>
196
+ ```
197
+
198
+ ```css
199
+ .pdf-table-frame { border: 0.3mm solid #d8dee9; border-radius: 3mm; }
200
+ .pdf-table { width: 100%; border-collapse: separate; border-spacing: 0; }
201
+ .pdf-col-label { width: 26%; }
202
+ .pdf-col-indicator { width: 24mm; }
203
+ .pdf-table th, .pdf-table td {
204
+ padding: 3mm;
205
+ border-bottom: 0.3mm solid #e8ecf2;
206
+ text-align: left;
207
+ vertical-align: top;
208
+ overflow-wrap: anywhere;
209
+ }
210
+ .pdf-table thead th { background-color: #172b4d; color: #fff; }
211
+ .pdf-table thead th:first-child { border-top-left-radius: 2.7mm; }
212
+ .pdf-table thead th:last-child { border-top-right-radius: 2.7mm; }
213
+ .pdf-table thead, .pdf-table tr {
214
+ break-inside: avoid;
215
+ page-break-inside: avoid;
216
+ }
217
+ .pdf-table tbody tr:nth-child(odd) > * { background-color: transparent; }
218
+ .pdf-table tbody tr:nth-child(even) > * { background-color: #f7f9fc; }
219
+ .pdf-indicator-cell { text-align: right; white-space: nowrap; }
220
+ ```
221
+
222
+ Declare tracks through `<colgroup>`; `table-layout: fixed` is not supported and may be diagnosed.
223
+ Apply header backgrounds and radii to `<th>` cells: a parent radius does not clip descendants
224
+ without `overflow: hidden`, which conflicts with fragmented tables; cell radii repeat with `thead`.
225
+
226
+ Let the table and `tbody` fragment while keeping individual rows intact. Add
227
+ `.pdf-atomic` to the frame only when the application can prove the complete
228
+ table fits on one page, using measured or bounded row heights. For long tables,
229
+ do not set `overflow: hidden` on the frame; clipping conflicts with
230
+ fragmentation. Transparent rows must retain painted-row geometry; if a background
231
+ changes cell width or alignment, treat it as a renderer regression, not a workaround.
232
+
233
+ ### Align legends, badges, and indicators
234
+
235
+ Use flex alignment and fixed geometry. Avoid baseline nudges, negative margins,
236
+ and transforms such as `translateY`.
237
+
238
+ ```css
239
+ .pdf-level, .pdf-legend-item {
240
+ display: inline-flex;
241
+ align-items: center;
242
+ gap: 1.5mm;
243
+ min-height: 5mm;
244
+ line-height: 1.2;
245
+ vertical-align: middle;
246
+ }
247
+ .pdf-dot {
248
+ display: inline-block;
249
+ flex: 0 0 3mm;
250
+ width: 3mm;
251
+ height: 3mm;
252
+ border-radius: 50%;
253
+ }
254
+ .pdf-dot-good { background-color: #16865c; }
255
+ ```
256
+
257
+ ### Avoid fragile PDF CSS
258
+
259
+ - Do not simulate a page with fixed heights such as `min-height: 940px`.
260
+ - Do not use `margin-top: auto`, empty blocks, or absolute positioning as a
261
+ pagination mechanism.
262
+ - Do not duplicate margins across `page.margin`, `@page`, and root padding.
263
+ - Do not put `overflow: hidden` on content that may fragment across pages.
264
+ - Do not use `line-height: 0`, transforms, or negative offsets to align icons.
265
+ - Scope report styles below `.pdf-document`; avoid host-wide `body` rules when
266
+ rendering a mounted fragment.
267
+ - Do not inject a complete `<html>` document into a generic `div`. Mount the
268
+ report subtree or pass a self-contained HTML string intentionally.
269
+
270
+ ### Validate production output
271
+
272
+ - Build with the production bundler and verify Worker and WASM asset loading.
273
+ - Inspect diagnostics and fail on unsupported layout when fidelity matters.
274
+ - Confirm text selection, links, and embedded fonts in the generated PDF.
275
+ - Test empty, short, and long data, including a table that spans pages and a
276
+ paragraph or list crossing a page boundary.
277
+ - Test `break-before: page` at page start with no extra blank; inspect every table page for one
278
+ repeated header, stable tracks, matching radii, preserved borders, and indicator alignment.
279
+ - Render with the same viewport, media type, fonts, and chart export strategy
280
+ used in production.
281
+
48
282
  ## Configuration reference
49
283
 
50
284
  Use these tables as the quick option reference. Treat the package's generated