Source: https://github.com/aipoch/medical-research-skills
Validation Shortcut
Run this minimal command first to verify the supported execution path:
python scripts/validate_skill.py --help
When to Use
- Export a web page (URL) to a PDF with Chrome-accurate rendering (CSS Grid/Flexbox, backgrounds, web fonts).
- Convert a local HTML report/invoice into a print-ready PDF (A4/Letter) with predictable margins and scaling.
- Generate single-page PDFs that must fit exactly on one page (posters, certificates, one-page invoices).
- Produce RTL documents (Hebrew/Arabic) where direction must be correct and fonts must render reliably.
- Render dynamic HTML that requires JavaScript execution before printing (charts, client-side templates).
Key Features
- Chrome-quality rendering via Puppeteer (headless Chromium/Chrome/Edge).
- Input flexibility: local HTML file, URL, or stdin (
-) piping.
- RTL support: automatic RTL detection with an option to force RTL (
--rtl).
- Print controls: format, landscape, margins (uniform or per-side), scale, background printing.
- Header/Footer templates: inject HTML header/footer.
- Stability for fonts/resources: waits for network idle and
document.fonts.ready, plus configurable extra wait.
Dependencies
- Node.js: >= 16 (recommended)
- npm: >= 8
- puppeteer: installed via
npm install (Chromium bundled by default)
- Optional browser executable (if not using bundled Chromium):
- Google Chrome or Microsoft Edge (path provided via
--executable-path or PUPPETEER_EXECUTABLE_PATH)
Example Usage
1) Install
cd d:/skills/html-to-pdf
npm install
2) Run (local HTML → PDF)
node assets/html-to-pdf.js input.html output.pdf
3) Run (URL → PDF)
node assets/html-to-pdf.js https://example.com page.pdf
4) Force RTL (Hebrew/Arabic)
node assets/html-to-pdf.js hebrew.html hebrew.pdf --rtl
5) Pipe HTML via stdin
echo "<h1>Example Title</h1>" | node assets/html-to-pdf.js - output.pdf --rtl
6) Use a specific browser executable (optional)
node assets/html-to-pdf.js https://example.com page.pdf --executable-path="C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
Or via environment variable:
set PUPPETEER_EXECUTABLE_PATH=C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
node assets/html-to-pdf.js https://example.com page.pdf
7) A complete, runnable single-page A4 example (recommended pattern)
Create single-page.html:
<!doctype html>
<html lang="he" dir="rtl">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="https://fonts.googleapis.com/css2?family=Heebo:wght@400;700&display=swap" rel="stylesheet">
<style>
@page { size: A4; margin: 0; }
/* Keep the page box exact; avoid backgrounds here to prevent extra pages */
html, body {
width: 210mm;
height: 297mm;
margin: 0;
padding: 0;
overflow: hidden;
}
/* Put backgrounds on a full-size container instead */
.container {
width: 100%;
height: 100%;
box-sizing: border-box;
padding: 20mm;
font-family: "Heebo", sans-serif;
direction: rtl;
text-align: right;
background: #f5f5f5;
overflow-wrap: break-word;
word-wrap: break-word;
}
</style>
</head>
<body>
<div class="container">
<h1>כותרת לדוגמה</h1>
<p>תוכן לדוגמה שמודפס כעמוד יחיד.</p>
</div>
</body>
</html>
Generate the PDF:
node assets/html-to-pdf.js single-page.html single-page.pdf --format=A4 --margin=0 --wait=1000
Implementation Details
Rendering approach
- Uses Puppeteer to load either:
- a local HTML file, or
- a remote URL, or
- HTML from stdin (
-)
- Wait strategy (to reduce missing fonts/assets):
- waits for
networkidle0 (resources finished loading),
- waits for
document.fonts.ready,
- then waits an additional
--wait=<ms> (default 1000) for late JS/font rendering.
RTL handling
- Default behavior: auto-detect RTL content (e.g., Hebrew/Arabic) and apply RTL direction.
- Override:
--rtl forces RTL regardless of detection.
Page-fit rule (single-page PDFs)
To avoid unexpected blank pages, ensure the content fits exactly within the page box:
- Do not set backgrounds on
html or body (common cause of extra pages).
- Put backgrounds on a full-height container (
.container) instead.
- Use
overflow: hidden on html, body for strict single-page output.
- If overflow persists, adjust:
--scale (e.g., 0.9, 0.8)
--margin (e.g., 10mm, 0)
CLI parameters
| Parameter |
Description |
Default |
--format=<format> |
Page size: A4, Letter, Legal, A3, A5 |
A4 |
--landscape |
Landscape orientation |
false |
--margin=<value> |
Uniform margin (e.g., 20mm, 1in) |
20mm |
--margin-top=<value> |
Top margin |
20mm |
--margin-right=<value> |
Right margin |
20mm |
--margin-bottom=<value> |
Bottom margin |
20mm |
--margin-left=<value> |
Left margin |
20mm |
--scale=<number> |
Scale factor (0.1-2.0) |
1 |
--background |
Print background graphics |
true |
--no-background |
Disable background printing |
- |
--header=<html> |
Header HTML template |
- |
--footer=<html> |
Footer HTML template |
- |
--wait=<ms> |
Extra wait time for fonts/JS |
1000 |
--rtl |
Force RTL direction |
Auto-detect |
Quality settings
- Uses Chrome print styles (
@page) and supports print CSS.
- Sets
deviceScaleFactor to 2 to improve output clarity.
Verification workflow (recommended)
After each generation, visually verify the PDF:
- No extra blank pages (vertical overflow).
- No clipped text (horizontal overflow).
- If issues occur, iterate up to 5 attempts:
- default
- reduce
--scale
- reduce
--margin
- reduce both further
- fix HTML/CSS (wrap long words, ensure container sizing)
If it still fails after 5 attempts, the HTML layout must be corrected (e.g., reduce fixed heights, fix oversized elements, ensure wrapping).
When Not to Use
- Do not use this skill when the required source data, identifiers, files, or credentials are missing.
- Do not use this skill when the user asks for fabricated results, unsupported claims, or out-of-scope conclusions.
- Do not use this skill when a simpler direct answer is more appropriate than the documented workflow.
Required Inputs
- A clearly specified task goal aligned with the documented scope.
- All required files, identifiers, parameters, or environment variables before execution.
- Any domain constraints, formatting requirements, and expected output destination if applicable.
Recommended Workflow
- Validate the request against the skill boundary and confirm all required inputs are present.
- Select the documented execution path and prefer the simplest supported command or procedure.
- Produce the expected output using the documented file format, schema, or narrative structure.
- Run a final validation pass for completeness, consistency, and safety before returning the result.
Output Contract
- Return a structured deliverable that is directly usable without reformatting.
- If a file is produced, prefer a deterministic output name such as
html_to_pdf_result.md unless the skill documentation defines a better convention.
- Include a short validation summary describing what was checked, what assumptions were made, and any remaining limitations.
Validation and Safety Rules
- Validate required inputs before execution and stop early when mandatory fields or files are missing.
- Do not fabricate measurements, references, findings, or conclusions that are not supported by the provided source material.
- Emit a clear warning when credentials, privacy constraints, safety boundaries, or unsupported requests affect the result.
- Keep the output safe, reproducible, and within the documented scope at all times.
Failure Handling
- If validation fails, explain the exact missing field, file, or parameter and show the minimum fix required.
- If an external dependency or script fails, surface the command path, likely cause, and the next recovery step.
- If partial output is returned, label it clearly and identify which checks could not be completed.
Quick Validation
Run this minimal verification path before full execution when possible:
No local script validation step is required for this skill.
Expected output format:
Result file: html_to_pdf_result.md
Validation summary: PASS/FAIL with brief notes
Assumptions: explicit list if any
Deterministic Output Rules
- Use the same section order for every supported request of this skill.
- Keep output field names stable and do not rename documented keys across examples.
- If a value is unavailable, emit an explicit placeholder instead of omitting the field.
Completion Checklist
- Confirm all required inputs were present and valid.
- Confirm the supported execution path completed without unresolved errors.
- Confirm the final deliverable matches the documented format exactly.
- Confirm assumptions, limitations, and warnings are surfaced explicitly.
1---2name: html-to-pdf3description: Convert HTML files or URLs to high-fidelity PDFs using Puppeteer; auto-detects or forces RTL for Hebrew/Arabic when RTL content is present.4license: MIT5---6> **Source**: [https://github.com/aipoch/medical-research-skills](https://github.com/aipoch/medical-research-skills)
7
8## Validation Shortcut
9
10Run this minimal command first to verify the supported execution path:
11
12```bash
13python scripts/validate_skill.py --help
14```
15
16## When to Use
17
18- Export a web page (URL) to a PDF with Chrome-accurate rendering (CSS Grid/Flexbox, backgrounds, web fonts).
19- Convert a local HTML report/invoice into a print-ready PDF (A4/Letter) with predictable margins and scaling.
20- Generate single-page PDFs that must fit *exactly* on one page (posters, certificates, one-page invoices).
21- Produce RTL documents (Hebrew/Arabic) where direction must be correct and fonts must render reliably.
22- Render dynamic HTML that requires JavaScript execution before printing (charts, client-side templates).
23
24## Key Features
25
26- **Chrome-quality rendering** via Puppeteer (headless Chromium/Chrome/Edge).
27- **Input flexibility**: local HTML file, URL, or stdin (`-`) piping.
28- **RTL support**: automatic RTL detection with an option to **force RTL** (`--rtl`).
29- **Print controls**: format, landscape, margins (uniform or per-side), scale, background printing.
30- **Header/Footer templates**: inject HTML header/footer.
31- **Stability for fonts/resources**: waits for network idle and `document.fonts.ready`, plus configurable extra wait.
32
33## Dependencies
34
35- **Node.js**: >= 16 (recommended)
36- **npm**: >= 8
37- **puppeteer**: installed via `npm install` (Chromium bundled by default)
38- Optional browser executable (if not using bundled Chromium):
39 - **Google Chrome** or **Microsoft Edge** (path provided via `--executable-path` or `PUPPETEER_EXECUTABLE_PATH`)
40
41## Example Usage
42
43### 1) Install
44
45```bash
46cd d:/skills/html-to-pdf
47npm install
48```
49
50### 2) Run (local HTML → PDF)
51
52```bash
53node assets/html-to-pdf.js input.html output.pdf
54```
55
56### 3) Run (URL → PDF)
57
58```bash
59node assets/html-to-pdf.js https://example.com page.pdf
60```
61
62### 4) Force RTL (Hebrew/Arabic)
63
64```bash
65node assets/html-to-pdf.js hebrew.html hebrew.pdf --rtl
66```
67
68### 5) Pipe HTML via stdin
69
70```bash
71echo "<h1>Example Title</h1>" | node assets/html-to-pdf.js - output.pdf --rtl
72```
73
74### 6) Use a specific browser executable (optional)
75
76```bash
77node assets/html-to-pdf.js https://example.com page.pdf --executable-path="C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
78```
79
80Or via environment variable:
81
82```bash
83set PUPPETEER_EXECUTABLE_PATH=C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
84node assets/html-to-pdf.js https://example.com page.pdf
85```
86
87### 7) A complete, runnable single-page A4 example (recommended pattern)
88
89Create `single-page.html`:
90
91```html
92<!doctype html>
93<html lang="he" dir="rtl">
94<head>
95 <meta charset="UTF-8" />
96 <meta name="viewport" content="width=device-width, initial-scale=1" />
97 <link href="https://fonts.googleapis.com/css2?family=Heebo:wght@400;700&display=swap" rel="stylesheet">
98 <style>
99 @page { size: A4; margin: 0; }
100
101 /* Keep the page box exact; avoid backgrounds here to prevent extra pages */
102 html, body {
103 width: 210mm;
104 height: 297mm;
105 margin: 0;
106 padding: 0;
107 overflow: hidden;
108 }
109
110 /* Put backgrounds on a full-size container instead */
111 .container {
112 width: 100%;
113 height: 100%;
114 box-sizing: border-box;
115 padding: 20mm;
116
117 font-family: "Heebo", sans-serif;
118 direction: rtl;
119 text-align: right;
120
121 background: #f5f5f5;
122 overflow-wrap: break-word;
123 word-wrap: break-word;
124 }
125 </style>
126</head>
127<body>
128 <div class="container">
129 <h1>כותרת לדוגמה</h1>
130 <p>תוכן לדוגמה שמודפס כעמוד יחיד.</p>
131 </div>
132</body>
133</html>
134```
135
136Generate the PDF:
137
138```bash
139node assets/html-to-pdf.js single-page.html single-page.pdf --format=A4 --margin=0 --wait=1000
140```
141
142## Implementation Details
143
144### Rendering approach
145
146- Uses **Puppeteer** to load either:
147 - a local HTML file, or
148 - a remote URL, or
149 - HTML from **stdin** (`-`)
150- Wait strategy (to reduce missing fonts/assets):
151 - waits for `networkidle0` (resources finished loading),
152 - waits for `document.fonts.ready`,
153 - then waits an additional `--wait=<ms>` (default `1000`) for late JS/font rendering.
154
155### RTL handling
156
157- Default behavior: **auto-detect** RTL content (e.g., Hebrew/Arabic) and apply RTL direction.
158- Override: `--rtl` forces RTL regardless of detection.
159
160### Page-fit rule (single-page PDFs)
161
162To avoid unexpected blank pages, ensure the content fits exactly within the page box:
163
164- Do **not** set backgrounds on `html` or `body` (common cause of extra pages).
165- Put backgrounds on a full-height container (`.container`) instead.
166- Use `overflow: hidden` on `html, body` for strict single-page output.
167- If overflow persists, adjust:
168 - `--scale` (e.g., `0.9`, `0.8`)
169 - `--margin` (e.g., `10mm`, `0`)
170
171### CLI parameters
172
173| Parameter | Description | Default |
174|---|---|---|
175| `--format=<format>` | Page size: A4, Letter, Legal, A3, A5 | A4 |
176| `--landscape` | Landscape orientation | false |
177| `--margin=<value>` | Uniform margin (e.g., `20mm`, `1in`) | 20mm |
178| `--margin-top=<value>` | Top margin | 20mm |
179| `--margin-right=<value>` | Right margin | 20mm |
180| `--margin-bottom=<value>` | Bottom margin | 20mm |
181| `--margin-left=<value>` | Left margin | 20mm |
182| `--scale=<number>` | Scale factor (0.1-2.0) | 1 |
183| `--background` | Print background graphics | true |
184| `--no-background` | Disable background printing | - |
185| `--header=<html>` | Header HTML template | - |
186| `--footer=<html>` | Footer HTML template | - |
187| `--wait=<ms>` | Extra wait time for fonts/JS | 1000 |
188| `--rtl` | Force RTL direction | Auto-detect |
189
190### Quality settings
191
192- Uses Chrome print styles (`@page`) and supports print CSS.
193- Sets `deviceScaleFactor` to **2** to improve output clarity.
194
195### Verification workflow (recommended)
196
197After each generation, visually verify the PDF:
198
199- No extra blank pages (vertical overflow).
200- No clipped text (horizontal overflow).
201- If issues occur, iterate up to 5 attempts:
202 1. default
203 2. reduce `--scale`
204 3. reduce `--margin`
205 4. reduce both further
206 5. fix HTML/CSS (wrap long words, ensure container sizing)
207
208If it still fails after 5 attempts, the HTML layout must be corrected (e.g., reduce fixed heights, fix oversized elements, ensure wrapping).
209
210## When Not to Use
211
212- Do not use this skill when the required source data, identifiers, files, or credentials are missing.
213- Do not use this skill when the user asks for fabricated results, unsupported claims, or out-of-scope conclusions.
214- Do not use this skill when a simpler direct answer is more appropriate than the documented workflow.
215
216## Required Inputs
217
218- A clearly specified task goal aligned with the documented scope.
219- All required files, identifiers, parameters, or environment variables before execution.
220- Any domain constraints, formatting requirements, and expected output destination if applicable.
221
222## Recommended Workflow
223
2241. Validate the request against the skill boundary and confirm all required inputs are present.
2252. Select the documented execution path and prefer the simplest supported command or procedure.
2263. Produce the expected output using the documented file format, schema, or narrative structure.
2274. Run a final validation pass for completeness, consistency, and safety before returning the result.
228
229## Output Contract
230
231- Return a structured deliverable that is directly usable without reformatting.
232- If a file is produced, prefer a deterministic output name such as `html_to_pdf_result.md` unless the skill documentation defines a better convention.
233- Include a short validation summary describing what was checked, what assumptions were made, and any remaining limitations.
234
235## Validation and Safety Rules
236
237- Validate required inputs before execution and stop early when mandatory fields or files are missing.
238- Do not fabricate measurements, references, findings, or conclusions that are not supported by the provided source material.
239- Emit a clear warning when credentials, privacy constraints, safety boundaries, or unsupported requests affect the result.
240- Keep the output safe, reproducible, and within the documented scope at all times.
241
242## Failure Handling
243
244- If validation fails, explain the exact missing field, file, or parameter and show the minimum fix required.
245- If an external dependency or script fails, surface the command path, likely cause, and the next recovery step.
246- If partial output is returned, label it clearly and identify which checks could not be completed.
247
248## Quick Validation
249
250Run this minimal verification path before full execution when possible:
251
252```text
253No local script validation step is required for this skill.
254```
255
256Expected output format:
257
258```text
259Result file: html_to_pdf_result.md
260Validation summary: PASS/FAIL with brief notes
261Assumptions: explicit list if any
262```
263
264## Deterministic Output Rules
265
266- Use the same section order for every supported request of this skill.
267- Keep output field names stable and do not rename documented keys across examples.
268- If a value is unavailable, emit an explicit placeholder instead of omitting the field.
269
270## Completion Checklist
271
272- Confirm all required inputs were present and valid.
273- Confirm the supported execution path completed without unresolved errors.
274- Confirm the final deliverable matches the documented format exactly.
275- Confirm assumptions, limitations, and warnings are surfaced explicitly.