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
热度 20.70
最近更新 2026-06-23 14:29:20
分类:效率依赖:代码执行 / 读写文件应用场景:文件转换

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add epub-to-pdf-skill
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