Skip to main content
Glama

html_to_pdf

Convert HTML files to PDF with print-aware styling, selectable Chromium or WeasyPrint rendering, color themes, and preserved clickable web and local links.

Instructions

Convert an HTML file (.html) to PDF with print-aware styling.

Supports two rendering engines:

- ``chromium`` (default): Uses Playwright headless Chromium.  Pixel-identical
  to Chrome Print → Save as PDF.  Supports all modern CSS.
  Requires: ``pip install playwright && playwright install chromium``.
- ``weasyprint``: Lightweight, good for simple documents.
  Replaces emoji with font-styled spans.  May not match Chrome perfectly
  for display:flex / display:grid layouts.

Ordinary HTML keeps its original styles. Recognized portable analytics
reports receive a scoped A4 print profile for typography, cards, charts,
and source deduplication. Chromium also converts very wide tables to
labeled record cards. Three color themes are available: white for printing,
warm sepia for low-glare reading, and One Dark Pro for dark-room reading.
Preserves clickable web and local file links, including paths into other
repositories. Relative links respect the source directory or HTML base URL.
Call inspect_pdf_links first. Local Markdown/HTML links prefer verified
existing PDFs. Multiple editions require pdf_targets; references without
PDFs and other formats keep the source file. Only authored static anchors
are inspected; script-created links need an authored equivalent or review.

Args:
    file_path:   Absolute path to the .html file.
    output_path: Absolute path for the output .pdf file.
                 If empty, derived from the source stem.
    engine:      Rendering backend: ``"chromium"`` or ``"weasyprint"``.
    theme:       Color theme: ``"print"`` (white, default), ``"sepia"``
                 (warm), or ``"one-dark-pro"`` (dark).
    pdf_targets: Reviewed source-to-PDF paths, or null values to keep sources.
                 Relative paths resolve from the source directory.
    pdf_destinations: Original hrefs mapped to fragments from resolve_pdf_destination.
    link_policy: "prefer-pdf" selects existing PDFs; "preserve" keeps sources.

Input Schema

NameRequiredDescriptionDefault
themeNoprint
engineNochromium
file_pathYes
link_policyNoprefer-pdf
output_pathNo
pdf_targetsNo
pdf_destinationsNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations exist, so the description carries the full burden, and it does so well: installation requirements for chromium, weasyprint's emoji replacement and flex/grid fidelity caveats, theme meanings, relative-link resolution, analytics-report print profiles, and wide-table-to-record-card conversion. It omits overwrite semantics and error behavior for a file-writing tool, keeping it below 5.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Purpose and engine choice are front-loaded, followed by bullet-style engine descriptions and a clean Args block. The link-handling paragraph is dense and prose-heavy, but nearly every sentence carries operational information; trimming the theme descriptions slightly would help.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 7-parameter, no-annotation, no-output-schema tool, the description covers engine prerequisites, theme semantics, link rewriting rules, and every argument. The remaining gaps are overwrite/error behavior and whether a result path is returned, which an agent would still need to discover.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so the Args block does the heavy lifting and documents all seven parameters, including defaults and the output_path derivation rule ('derived from the source stem'). pdf_targets ('null values to keep sources', relative resolution) and pdf_destinations ('hrefs mapped to fragments from resolve_pdf_destination') are explained, though the exact map shape could be clearer.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('Convert an HTML file (.html) to PDF') plus the differentiator 'print-aware styling'. The multi-paragraph body makes clear this is the HTML-source converter, distinct from siblings like markdown_to_pdf, and names inspect_pdf_links and resolve_pdf_destination as upstream steps.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives explicit routing guidance: engine trade-offs (chromium pixel-identical vs weasyprint lightweight/limited), 'Call inspect_pdf_links first', 'Multiple editions require pdf_targets', and link_policy semantics. It stops short of stating when to prefer markdown_to_pdf or pdf_to_text instead, so not a full 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.