文章目录
mkdocs-with-pdf 0.9.3的安装使用
概述
本来想将目录下的多个.md分别转成多个pdf文件.
看到 mkdocs-with-pdf插件, 试试.
最后发现, 只能将所有的.md都转成一个pdf, 不是我想要的效果.
刚开始使用时, 各种报错. 用了一上午, 将mkdocs-with-pdf的使用问题解决了.
虽然不是我要的效果, 但是初步安装使用 mkdocs-with-pdf时遇到了问题, 将解决过程记录一下.
笔记
最后解决问题时, 还是得看的官方文档, 看零散资料不管用.
官方文档url https://pypi.org/project/mkdocs-with-pdf/
安装前置条件
This package requires MkDocs version 1.0 or higher (0.17 works as well)
我安装的mkdocs版本是1.4.0
Python 3.6 or higher
我安装了python3.10.x
Z:\>python -V
Python 3.10.7
WeasyPrint
WeasyPrint depends on cairo, Pango and GDK-PixBuf which need to be installed separately. Please follow the installation instructions for your platform carefully:
先看看WeasyPrint是否安装了
但是这里有个坑, 就是安装了WeasyPrint, 还需要安装GTK3.x的运行时库.
必须按照自己的系统去安装GTK3.x的运行时库.
https://doc.courtbouillon.org/weasyprint/latest/first_steps.html#windows
相当于安装GTK3运行时库是安装 WeasyPrint的前置条件.
下载后为 gtk3-runtime-3.24.31-2022-01-04-ts-win64.exe, 安装.
如果不安装gtk3运行时库, 或者安装的是旧版gtk运行时库, 编译就会报错, 说 gobject-2.0-0 库无法载入.
mkdocs.yml的配置
插件的名称为 with-pdf
# Plugins
plugins:
- search:
separator: '[\s\u200b\-]'
- with-pdf:
verbose: true
编译
mkdocs build
Z:\>mkdocs build
INFO - Cleaning site directory
INFO - Building documentation to directory: Z:\site
...
INFO - Converting 6 articles to PDF took 5.5s
INFO - Documentation built in 6.94 seconds
Z:\>
生成后的pdf位置
在site\pdf路径下, 有生成好的pdf