开发者文档

开发文档与参考手册(v1.5.0)

Oxtail 在进程内将 HTML5 & CSS 直接编译为确定性 PDF 1.7 字节流,显式传入字体与资源并执行严格内存上限。以闭源预构建 C ABI v1 库(libhtml_to_pdf)、WebAssembly(oxtail-html-to-pdf)以及 15 MB 独立 CLI 二进制文件形式分发。

30 天评估与发布归档包

立即在在线 WebAssembly 体验区测试你的 HTML/CSS,或依据个人许可证开展 30 天企业内部评估。如需在公共镜像同步前提前获取预构建发布包(Linux、macOS、Windows),请发邮件至 sales@oxtailpdf.com。

1. 按语言安装与集成

1. 安装
2. 集成

Supported Targets & Package Registries

Every native release ships both Linux x86_64 and Linux ARM64 (aarch64) across every registry and package manager automatically, while the WebAssembly package runs identically on macOS, Windows, Linux, Node.js, Deno, Bun, Workers, and Browsers.

Ecosystem Targets Shipped Registries / Channels
CLI (html-to-pdf)linux-x86_64, linux-arm64install.sh, Homebrew (oxbloom/tap), Arch AUR, Direct Downloads, GitLab Releases
JS / Wasm (oxtail-html-to-pdf)Universal wasm32 (all OS & CPUs)Oxbloom Registry, oxtailpdf.com/npm, Direct Downloads
Python (oxtail-html-to-pdf)manylinux_2_28_x86_64, manylinux_2_28_aarch64PyPI, Oxbloom Registry, oxtailpdf.com/pypi/
.NET 8 (Oxtail.HtmlToPdf)linux-x64, linux-arm64 (single multi-RID .nupkg)Oxbloom Registry, oxtailpdf.com/nuget/v3/index.json
Java 17+ (com.oxtailpdf:html-to-pdf)linux-x86_64, linux-aarch64 (single fat JAR + JNI)Oxbloom Registry, oxtailpdf.com/maven
Ruby 3.1+ (oxtail_html_to_pdf)x86_64-linux, aarch64-linuxRubyGems, Oxbloom Registry, oxtailpdf.com/gems/
Rust / Go / C / C++linux-x86_64, linux-arm64 (libhtml_to_pdf.so)Oxbloom Registry, oxtailpdf.com/cargo/, go get oxtailpdf.com/htmltopdf, Direct Downloads

2. CLI 参考(html-to-pdf)

用法:html-to-pdf [OPTIONS] <input.html>

参数 默认值 说明
-o, --output FILE<input>.pdf将渲染后的 PDF 字节流写入 FILE。
--paper a3|a4|a5|letter|legala4默认物理纸张尺寸(若 CSS 中声明了 @page { size } 则以其为准)。
--margin LENGTH0.7in使用 CSS 长度单位(mm、in 或 pt)设置页边距。
--media print|screenprint按 print 或 screen 媒体模式求值 CSS @media 规则。
--print-backgrounds关闭在打印模式下绘制背景色与背景图片。
--tagged关闭输出 PDF 1.7 结构树标签,提供无障碍阅读顺序支持。
--document-outline关闭根据 h1–h6 标题自动生成 PDF 书签大纲。
--js关闭执行受限的文档脚本(为防范不可信 HTML,默认关闭)。
--font-dir DIR无显式指定的有序 .ttf/.otf 字体目录(不扫描系统环境字体)。
--resource-dir DIR无用于图片与样式表的本地资源目录(默认拦截路径穿越)。
--trusted-root DIR无提供所有本地引用资源类型的 Web 根目录。
--base-url URLhttps://localhost/...用于解析相对链接与资源的规范基础 URL。
--list-pages关闭向标准输出打印 N pages,不写入 PDF 文件。

PDF-Only CSS: @media pdf-render & pdf-visibility

Keep your normal browser screen and @media print stylesheets completely untouched while applying styles that run only when Oxtail renders a PDF. Standard browsers ignore @media pdf-render (per CSS Media Queries Level 4), while Oxtail always evaluates pdf-render to true in both --media print and --media screen modes—including <style media="pdf-render"> and <link rel="stylesheet" media="pdf-render">.

styles.css — styles applied only during Oxtail PDF rendering
/* Ignored by Chrome/Safari/Firefox; always active inside Oxtail */
@media pdf-render {
  @page {
    size: A4;
    margin: 16mm 14mm;
  }

  /* Hide web-only navigation, sticky toolbars, or interactive controls */
  .web-nav,
  .download-pdf-btn {
    display: none;
  }

  /* Show PDF-only footers, signature blocks, or watermarks */
  .pdf-signature-block {
    display: block;
    break-inside: avoid;
  }
}

/* Render-time visibility override (values: visible | hidden | none; inherited) */
.interactive-widget {
  pdf-visibility: none;   /* omitted from PDF layout; visible in browsers */
}
.draft-stamp {
  pdf-visibility: visible;
}

@media pdf-render vs @media print

Use standard @media print for shared browser print styles, and layer @media pdf-render (or pdf-visibility: none | hidden | visible) when you want exact PDF-only pagination, headers, or UI suppression without changing what users see when hitting Ctrl+P in a browser.

3. 图片、Logo 与多字重字体

Oxtail 绝不会主动发起外发 HTTP 请求或自动读取宿主机字体。日常 SDK 开发中,可直接通过高级 API 传入字体(JS 为 renderPdf,Python/Rust 为 render_pdf,Go/.NET 为 Render,Ruby/Java/C++ 为 render)。如需使用自定义图片、外部样式表、严格页数/内存限制或直接调用原始 C ABI,可通过内联 <svg> / data: URI 或底层 h2p-ffi-request/1 请求信封提供资源:

h2p-ffi-request/1 — 多字重字体 + PNG Logo + 显式资源预算
{
  "schema": "h2p-ffi-request/1",
  "document_utf8": "<!doctype html><img src=\"https://app.local/logo.png\" width=\"120\"><h1>Invoice</h1>",
  "environment": {
    "paper_width_milli_points": 595440,
    "paper_height_milli_points": 841680,
    "media_type": "print",
    "print_backgrounds": true,
    "tagging_mode": "tagged",
    "document_outline": true
  },
  "limits": { "max_pages": 250, "max_document_bytes": 10485760 },
  "resources": [
    { "url": "https://app.local/logo.png", "kind": "image", "mime_type": "image/png", "requirement": "required", "data_base64": "..." },
    { "url": "https://app.local/Inter-Regular.ttf", "kind": "font", "mime_type": "font/ttf", "requirement": "required", "data_base64": "..." },
    { "url": "https://app.local/Inter-Bold.ttf", "kind": "font", "mime_type": "font/ttf", "requirement": "required", "data_base64": "..." }
  ],
  "font_faces": [
    { "resource_url": "https://app.local/Inter-Regular.ttf", "family": "Inter", "style": "normal", "weight": 400, "generic_families": ["sans-serif"] },
    { "resource_url": "https://app.local/Inter-Bold.ttf", "family": "Inter", "style": "normal", "weight": 700, "generic_families": ["sans-serif"] }
  ]
}

纸张尺寸单位:paper_width_milli_points / paper_height_milli_points 以千分之一 PDF 点(1/72 英寸)计:A4 为 595440 × 841680;US Letter 为 612000 × 792000。你也可以直接在 CSS 中通过 @page { size: A4; margin: 14mm; } 指定物理尺寸。

流式会话:除单次调用 render_preloaded 外,C ABI v1 还暴露了可恢复的会话状态机(create → step → supply / drain → finish / free),支持宿主端带背压地流式读取大型输出、按需供给资源并干净地取消渲染。

4. 支持的能力与明确边界

领域 当前状态(v1.5.0)
HTML 与现代 CSS HTML5 解析、CSS 级联/图层/自定义属性/calc()/逻辑属性、CSS Grid、Flexbox、浮动、跨页表格、变换、渐变、clip-path、@page 尺寸、页边距框与页码计数器。
图形与图像 内联 SVG、PNG、JPEG 及光栅/矢量绘制内容均直接输出为真实的 PDF 矢量路径、图像与可选中文本(绝非整页截图)。
字体与排版 支持显式 .ttf / .otf 字体塑形、子集嵌入及 ToUnicode CMap,确保文本复制与搜索准确清晰。请显式传入所需的全部字重与文字系统字体。
JavaScript 执行 出于安全考虑默认关闭。受限脚本执行需显式开启(--js / js_enabled: true);Oxtail 并非交互式实时 SPA 浏览器或无头网页爬虫。
PDF 标准 确定性 PDF 1.7(sRGB),可选结构树(--tagged)与标题大纲(--document-outline)。暂未包含 PDF/A 归档规范、PDF/X CMYK 印刷输出与 PDF 加密。
网络与宿主隔离 零外发网络请求、零隐式文件系统读取、零操作系统字体扫描。不会自动拉取外部 Google Fonts 或 CDN 链接——请显式打包所需资源。

5. 安全性、校验和与发布溯源

每个官方发布归档均附带确定性 SHA256SUMS(可选独立 GPG 签名)、第三方归属声明与开源许可清单(NOTICE.txt 与 SOURCES.md),且不含任何遥测或回传行为。如需报告安全漏洞或索取供应商合规文档,请致信 security@oxtailpdf.com。

想立刻测试你的 HTML?

将你的代码粘贴到在线 WebAssembly 体验区,直接在浏览器中实测渲染耗时、峰值内存与 PDF 输出效果。