@imggion/html2realpdf 0.1.14-rc1 → 0.1.14-rc2

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-rc2",
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,237 @@ 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 {
201
+ width: 100%;
202
+ border-collapse: collapse;
203
+ table-layout: fixed;
204
+ }
205
+ .pdf-col-label { width: 26%; }
206
+ .pdf-col-indicator { width: 24mm; }
207
+ .pdf-table th, .pdf-table td {
208
+ padding: 3mm;
209
+ border-bottom: 0.3mm solid #e8ecf2;
210
+ text-align: left;
211
+ vertical-align: top;
212
+ overflow-wrap: anywhere;
213
+ }
214
+ .pdf-table thead, .pdf-table tr {
215
+ break-inside: avoid;
216
+ page-break-inside: avoid;
217
+ }
218
+ .pdf-table tbody tr:nth-child(odd) { background-color: #fff; }
219
+ .pdf-table tbody tr:nth-child(even) { background-color: #f7f9fc; }
220
+ .pdf-indicator-cell { text-align: right; white-space: nowrap; }
221
+ ```
222
+
223
+ Let the table and `tbody` fragment while keeping individual rows intact. Add
224
+ `.pdf-atomic` to the frame only when the application can prove the complete
225
+ table fits on one page, using measured or bounded row heights. For long tables,
226
+ do not set `overflow: hidden` on the frame; clipping conflicts with
227
+ fragmentation. Explicitly paint both odd and even row states so pagination does
228
+ not depend on a transparent inherited surface.
229
+
230
+ ### Align legends, badges, and indicators
231
+
232
+ Use flex alignment and fixed geometry. Avoid baseline nudges, negative margins,
233
+ and transforms such as `translateY`.
234
+
235
+ ```css
236
+ .pdf-level, .pdf-legend-item {
237
+ display: inline-flex;
238
+ align-items: center;
239
+ gap: 1.5mm;
240
+ min-height: 5mm;
241
+ line-height: 1.2;
242
+ vertical-align: middle;
243
+ }
244
+ .pdf-dot {
245
+ display: inline-block;
246
+ flex: 0 0 3mm;
247
+ width: 3mm;
248
+ height: 3mm;
249
+ border-radius: 50%;
250
+ }
251
+ .pdf-dot-good { background-color: #16865c; }
252
+ ```
253
+
254
+ ### Avoid fragile PDF CSS
255
+
256
+ - Do not simulate a page with fixed heights such as `min-height: 940px`.
257
+ - Do not use `margin-top: auto`, empty blocks, or absolute positioning as a
258
+ pagination mechanism.
259
+ - Do not duplicate margins across `page.margin`, `@page`, and root padding.
260
+ - Do not put `overflow: hidden` on content that may fragment across pages.
261
+ - Do not use `line-height: 0`, transforms, or negative offsets to align icons.
262
+ - Scope report styles below `.pdf-document`; avoid host-wide `body` rules when
263
+ rendering a mounted fragment.
264
+ - Do not inject a complete `<html>` document into a generic `div`. Mount the
265
+ report subtree or pass a self-contained HTML string intentionally.
266
+
267
+ ### Validate production output
268
+
269
+ - Build with the production bundler and verify Worker and WASM asset loading.
270
+ - Inspect diagnostics and fail on unsupported layout when fidelity matters.
271
+ - Confirm text selection, links, and embedded fonts in the generated PDF.
272
+ - Test empty, short, and long data, including a table that spans pages and a
273
+ paragraph or list crossing a page boundary.
274
+ - Inspect first, continuation, and final pages for repeated headers, clipped
275
+ borders, blank pages, and row or legend alignment.
276
+ - Render with the same viewport, media type, fonts, and chart export strategy
277
+ used in production.
278
+
48
279
  ## Configuration reference
49
280
 
50
281
  Use these tables as the quick option reference. Treat the package's generated