Html to pdf

From aipoch/medical-research-skills · View interactive version

Html to pdf is an AI agent skill from the GitHub repository aipoch/medical-research-skills. Convert HTML files or URLs to high-fidelity PDFs using Puppeteer; auto-detects or forces RTL for Hebrew/Arabic when RTL content is present.

How to use this skill

Skill file

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

Key Features

Dependencies

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

RTL handling

Page-fit rule (single-page PDFs)

To avoid unexpected blank pages, ensure the content fits exactly within the page box:

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

Verification workflow (recommended)

After each generation, visually verify the PDF:

1. default

2. reduce --scale

3. reduce --margin

4. reduce both further

5. 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

Required Inputs

Recommended Workflow

  1. Validate the request against the skill boundary and confirm all required inputs are present.
  2. Select the documented execution path and prefer the simplest supported command or procedure.
  3. Produce the expected output using the documented file format, schema, or narrative structure.
  4. Run a final validation pass for completeness, consistency, and safety before returning the result.

Output Contract

Validation and Safety Rules

Failure Handling

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

Completion Checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.