360 Secure SkillHub
360 安全技能中心

epub-to-pdf-skill

通过 Python 脚本把 .epub 文件转换为 PDF:用 ebooklib 读取文档条目,BeautifulSoup 配合 lxml 清理 script/style 等标签,注入 CJK 字体 @font-face 后用 WeasyPrint 渲染为 A4、2cm 页边距、两端对齐的 PDF。需预先安装 weasyprint、ebooklib、beautifulsoup4、lxml,并依赖…

分类:效率
hellobigbean
hellobigbean
热度 13.15
最近更新 2026-06-23 14:29:20

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add hellobigbean/epub-to-pdf-skill
兼容性
OpenClaw 专属
联网要求
不联网
数据出网
数据不出本机
Metadata
name
epub-to-pdf
description
Convert EPUB e-books to PDF using ebooklib + WeasyPrint with proper CJK font support.

EPUB → PDF

Convert .epub files to PDF. Works for Chinese/Japanese/Korean text.

Prerequisites

apt-get install -y weasyprint
pip3 install --break-system-packages ebooklib beautifulsoup4 lxml

CJK fonts required:

  • /root/.openclaw/workspace/skills/pdf-maker/NotoSansCJKsc.ttf
  • /root/.openclaw/workspace/skills/pdf-maker/NotoSansCJKscB.ttf

Usage

python3 scripts/epub2pdf.py <input.epub> <output.pdf>

How it works

  1. ebooklib reads all ITEM_DOCUMENT entries from the EPUB
  2. BeautifulSoup + lxml strips <script>, <style>, <link>, <meta> tags
  3. Injects CJK fonts via @font-face CSS
  4. WeasyPrint renders combined HTML to A4 PDF (2cm margins, justified)

Troubleshooting

Symptom Fix
WeasyPrint import fails apt-get install weasyprint
CJK characters garbled Ensure font TTF path is correct (TTC collections won't work)
Empty / tiny PDF EPUB has no readable document entries — check TNC count
calibre root sandbox error Don't use calibre; use this script instead