html-to-pdf

GitHub

将HTML和CSS渲染为PDF文件,适用于导出带样式的报告、发票或标签。基于WeasyPrint,支持分页媒体CSS属性。

src/opensquilla/skills/bundled/html-to-pdf/SKILL.md opensquilla/opensquilla

Trigger Scenarios

用户希望将HTML页面或模板导出为PDF格式 需要将带样式的文档(如报表、发票)转换为可打印的PDF

Install

npx skills add opensquilla/opensquilla --skill html-to-pdf -g -y
More Options

Non-standard path

npx skills add https://github.com/opensquilla/opensquilla/tree/main/src/opensquilla/skills/bundled/html-to-pdf -g -y

Use without installing

npx skills use opensquilla/opensquilla@html-to-pdf

指定 Agent (Claude Code)

npx skills add opensquilla/opensquilla --skill html-to-pdf -a claude-code -g -y

安装 repo 全部 skill

npx skills add opensquilla/opensquilla --all -g -y

预览 repo 内 skill

npx skills add opensquilla/opensquilla --list

SKILL.md

Frontmatter
{
    "name": "html-to-pdf",
    "homepage": "https:\/\/weasyprint.org\/",
    "metadata": {
        "platform": {
            "emoji": "📄",
            "install": [
                {
                    "id": "weasyprint",
                    "kind": "uv",
                    "label": "Install WeasyPrint (uv pip)",
                    "package": "weasyprint"
                }
            ],
            "requires": {
                "anyBins": [
                    "python",
                    "python3"
                ]
            }
        }
    },
    "provenance": {
        "origin": "clawhub-mit0",
        "license": "MIT-0",
        "upstream_url": "https:\/\/clawhub.ai\/generate-pdf",
        "maintained_by": "OpenSquilla"
    },
    "description": "Render HTML (with CSS) to a PDF file. Trigger when the user wants to export a styled report, invoice, label, or any HTML\/Jinja-rendered page to PDF. Uses WeasyPrint, which supports a meaningful subset of CSS Paged Media (page size, margins, headers\/footers, page-break-before\/after). Optional dependency — install via `pip install opensquilla[document-extras]` or `uv add weasyprint` because WeasyPrint pulls in native libraries (Pango, Cairo, fontconfig) that need OS-level packages."
}

html-to-pdf

Render HTML + CSS to PDF using WeasyPrint. Best for static report exports where the source already exists in HTML form (templates, dashboards, invoices). For programmatic PDF assembly from data structures, use the pdf-toolkit skill's reportlab path instead.

Delivery rule

First, use the available tool list for this session to choose the delivery path.

If write_file, edit_file, apply_patch, or execute_code is available:

  • Build the .pdf, .html, or requested file in the active workspace using the workflow below.
  • Call publish_artifact for the final file before your final reply when that tool is available.
  • The examples and workflow steps later in this document apply.

If none of those file-authoring tools are available:

  • Do not attempt to generate, save, or modify the final file.
  • Do not paste the full HTML/CSS source into chat as a substitute for delivering the file.
  • Ignore the Quick start and Workflow sections below; they do not apply when file authoring is unavailable.
  • Reply plainly: explain that the current session cannot create files, and offer to publish an existing file by path, describe the document contents in text, or continue in a file-authoring surface such as the OpenSquilla Web UI.

In all cases, do not paste full file source as the deliverable. Source code is appropriate only when the user explicitly asks for code.

Use cases

  • HTML/Jinja template + content → styled PDF report
  • Markdown rendered to HTML → printable PDF
  • Email content → archival PDF
  • Generated dashboards (HTML + screenshots) → shareable PDF

Limitations

  • Source data is structured (JSON, dataframe) with no HTML — use pdf-toolkit (reportlab) directly instead.
  • Source PDF needs editing — use pdf-toolkit (pypdf path).
  • Need pixel-perfect Word-style document layout — use the docx skill.
  • Need dynamic JavaScript-driven content — WeasyPrint does not execute JS; pre-render with a headless browser first.

Quick start

python {baseDir}/scripts/render.py --html report.html --out report.pdf
python {baseDir}/scripts/render.py --html invoice.html --out invoice.pdf --page-size A4

The script accepts a local file path, a file:// URL, or an http(s):// URL. CSS is loaded relative to the HTML location for local paths; for URLs, the same fetch rules apply (network resources are loaded with WeasyPrint's default fetcher).

CSS Paged Media support

WeasyPrint implements the parts of CSS that matter for paged output:

  • @page rule with size, margin, @top-center, @bottom-right boxes
  • Page breaks: page-break-before, page-break-after, break-inside: avoid
  • Counters: counter(page), counter(pages)
  • prince- properties: WeasyPrint supports many but not all PrinceXML extensions

Example header/footer setup:

@page {
  size: Letter;
  margin: 1in;
  @top-center { content: "Q3 Review — Confidential"; }
  @bottom-right { content: "Page " counter(page) " of " counter(pages); }
}

Cross-platform install hints

WeasyPrint is pure Python but depends on native libraries. The OpenSquilla install spec only triggers pip install weasyprint; the OS packages must be installed separately.

macOS

brew install pango cairo gdk-pixbuf libffi

Debian/Ubuntu

sudo apt-get install -y libpango-1.0-0 libpangoft2-1.0-0 \
    libharfbuzz0b libfontconfig1

Windows

The simplest path is the GTK runtime via winget:

winget install --id GTK.GTK3

Or use MSYS2's mingw-w64-x86_64-pango package and ensure its bin/ directory is on PATH. WeasyPrint ≥61 ships an alternate "lite" path that bundles its own native libs on Windows; check WeasyPrint's installation docs for the current state.

If the render.py script raises OSError: cannot load library, the native libs are not on the search path — the user must install them per the platform instructions above.

Boundaries

  • Does not execute JavaScript. Pre-render dynamic content with a headless browser first, then feed the resulting HTML to this skill.
  • Does not support every CSS feature — flexbox and grid have known limitations in paged contexts. Test layout before relying on either.
  • Font availability is OS-dependent. To guarantee reproducibility, embed fonts via @font-face with absolute paths or data URIs.
  • For high-volume PDF generation (hundreds of documents per minute), prefer a service-grade renderer (PrinceXML, browser-based pipelines). WeasyPrint is the right tool for tens to a few hundred PDFs per run.

Version History

  • 7f72a32 Current 2026-07-05 18:38

Same Skill Collection

src/opensquilla/skills/bundled/advanced-dubbing-studio/SKILL.md
src/opensquilla/skills/bundled/ai-video-script/SKILL.md
src/opensquilla/skills/bundled/audio-cog/SKILL.md
src/opensquilla/skills/bundled/awesome-webpage-image-download/SKILL.md
src/opensquilla/skills/bundled/awesome-webpage-research/SKILL.md
src/opensquilla/skills/bundled/AwesomeWebpageMetaSkill/SKILL.md
src/opensquilla/skills/bundled/cron/SKILL.md
src/opensquilla/skills/bundled/docx/SKILL.md
src/opensquilla/skills/bundled/filesystem/SKILL.md
src/opensquilla/skills/bundled/git-diff/SKILL.md
src/opensquilla/skills/bundled/github/SKILL.md
src/opensquilla/skills/bundled/history-explorer/SKILL.md
src/opensquilla/skills/bundled/html-coder/SKILL.md
src/opensquilla/skills/bundled/http-fetch/SKILL.md
src/opensquilla/skills/bundled/latex-compile/SKILL.md
src/opensquilla/skills/bundled/memory/SKILL.md
src/opensquilla/skills/bundled/music-and-singing-studio/SKILL.md
src/opensquilla/skills/bundled/nano-banana-pro-openrouter/SKILL.md
src/opensquilla/skills/bundled/nano-banana-pro/SKILL.md
src/opensquilla/skills/bundled/nano-pdf/SKILL.md
src/opensquilla/skills/bundled/openrouter-video-generator/SKILL.md
src/opensquilla/skills/bundled/paper-abstract-author/SKILL.md
src/opensquilla/skills/bundled/paper-citation-planner/SKILL.md
src/opensquilla/skills/bundled/paper-experiment-stub/SKILL.md
src/opensquilla/skills/bundled/paper-outline-author/SKILL.md
src/opensquilla/skills/bundled/paper-preference-planner/SKILL.md
src/opensquilla/skills/bundled/paper-refbib-stub/SKILL.md
src/opensquilla/skills/bundled/paper-revision-author/SKILL.md
src/opensquilla/skills/bundled/paper-section-author/SKILL.md
src/opensquilla/skills/bundled/paper-source-curator/SKILL.md
src/opensquilla/skills/bundled/pptx/SKILL.md
src/opensquilla/skills/bundled/seedance-2-prompt/SKILL.md
src/opensquilla/skills/bundled/skill-creator-linter/SKILL.md
src/opensquilla/skills/bundled/skill-creator-proposals/SKILL.md
src/opensquilla/skills/bundled/skill-creator-smoke-test/SKILL.md
src/opensquilla/skills/bundled/srt-from-script/SKILL.md
src/opensquilla/skills/bundled/stack-trace-generic-probe/SKILL.md
src/opensquilla/skills/bundled/stack-trace-go-probe/SKILL.md
src/opensquilla/skills/bundled/stack-trace-js-probe/SKILL.md
src/opensquilla/skills/bundled/stack-trace-python-probe/SKILL.md
src/opensquilla/skills/bundled/stack-trace-rust-probe/SKILL.md
src/opensquilla/skills/bundled/subtitle-burner/SKILL.md
src/opensquilla/skills/bundled/swe-bench/SKILL.md
src/opensquilla/skills/bundled/text-file-read/SKILL.md
src/opensquilla/skills/bundled/title-card-image/SKILL.md
src/opensquilla/skills/bundled/video-merger/SKILL.md
src/opensquilla/skills/bundled/video-still-animator/SKILL.md
src/opensquilla/skills/bundled/voice-clone-lab/SKILL.md
src/opensquilla/skills/bundled/voice-conversion-studio/SKILL.md
src/opensquilla/skills/bundled/voiceover-studio/SKILL.md
src/opensquilla/skills/bundled/weather/SKILL.md
src/opensquilla/skills/bundled/web-search/SKILL.md
src/opensquilla/skills/bundled/xlsx/SKILL.md
src/opensquilla/skills/exp/meta-arxiv-daily-digest-deck/SKILL.md
src/opensquilla/skills/exp/meta-codereview-current-diff/SKILL.md
src/opensquilla/skills/exp/meta-compliance-audit-bundle/SKILL.md
src/opensquilla/skills/exp/meta-diagram-triangulation/SKILL.md
src/opensquilla/skills/exp/meta-github-pr-watch-digest/SKILL.md
src/opensquilla/skills/exp/meta-issue-to-pr-autopilot/SKILL.md
src/opensquilla/skills/exp/meta-knowledge-base-bootstrap/SKILL.md
src/opensquilla/skills/exp/meta-migration-assistant/SKILL.md
src/opensquilla/skills/exp/meta-multi-format-export-pack/SKILL.md
src/opensquilla/skills/exp/meta-pdf-intelligence/SKILL.md
src/opensquilla/skills/exp/meta-pdf-reformat-pipeline/SKILL.md
src/opensquilla/skills/exp/meta-pre-commit-quality-gate/SKILL.md
src/opensquilla/skills/exp/meta-scheduled-morning-digest/SKILL.md
src/opensquilla/skills/exp/meta-security-review-bundle/SKILL.md
src/opensquilla/skills/exp/meta-spreadsheet-insight/SKILL.md
src/opensquilla/skills/exp/meta-stack-trace-investigator/SKILL.md
src/opensquilla/skills/exp/meta-travel-planner/SKILL.md
src/opensquilla/skills/exp/meta-web-to-pdf-briefing/SKILL.md
tests/_fixtures/meta-paper-write-handwritten.SKILL.md
src/opensquilla/skills/bundled/code-task/SKILL.md
src/opensquilla/skills/bundled/deep-research/SKILL.md
src/opensquilla/skills/bundled/meta-kid-project-planner/SKILL.md
src/opensquilla/skills/bundled/meta-paper-write/SKILL.md
src/opensquilla/skills/bundled/meta-short-drama/SKILL.md
src/opensquilla/skills/bundled/meta-skill-creator/SKILL.md
src/opensquilla/skills/bundled/multi-search-engine/SKILL.md
src/opensquilla/skills/bundled/pdf-toolkit/SKILL.md
src/opensquilla/skills/bundled/skill-creator/SKILL.md
src/opensquilla/skills/bundled/sub-agent/SKILL.md
src/opensquilla/skills/bundled/summarize/SKILL.md
src/opensquilla/skills/bundled/tmux/SKILL.md
src/opensquilla/skills/exp/meta-long-running-build-watchdog/SKILL.md
src/opensquilla/skills/bundled/paper-plot-stub/SKILL.md
src/opensquilla/skills/exp/meta-content-publish-pipeline/SKILL.md
src/opensquilla/skills/exp/meta-home-it-rescue/SKILL.md
src/opensquilla/skills/exp/meta-meeting-to-workflow/SKILL.md
src/opensquilla/skills/exp/meta-research-to-slide-deck/SKILL.md
src/opensquilla/skills/exp/meta-sales-lead-researcher/SKILL.md

Metadata

Files
0
Version
7f72a32
Hash
422dc633
Indexed
2026-07-05 18:38

trang chủ - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-07-09 02:12
浙ICP备14020137号-1 $bản đồ khách truy cập$