目前,我正在使用mkdocs-material
来使用美人鱼图,配置如下(在mkdocs.yml
中):
...
markdown_extensions:
- pymdownx.superfences:
custom_fences:
- name: mermaid
class: mermaid
...
但是,我遇到PDF导出方面的问题。
我试过几个插件。它们中的大多数依赖于Weasy,并且在javascript部件或人鱼图(没有呈现,并且仍然处于代码块的样式中)方面存在问题。有一个插件(mkdocs-pdf与-js-plugin)以一种简单简单的方式打印页面,它使用浏览器来完成这项工作。但是,它不包含我所需要的作为combined
包的mkdocs-pdf-导出-插件特性(将所有页面合并到一个PDF文件中)。
有没有其他插件支持导出PDF与美人鱼关系图,并结合功能?
发布于 2022-12-04 15:11:20
我现在的解决办法
运行:ENABLE_PDF_EXPORT=1 mkdocs build
。每个标记文件将被导出到一个PDF文件。
然后,通过将PDF名称从上到下放入一个唯一文件中,我将定义所有PDF的顺序:
在chapters.txt
中
A.pdf
B.pdf
C.pdf
...
然后运行以下脚本。请记住,这个脚本只是我所做工作的一个提示,它还没有完成,也没有运行“原样”。
# ================================================================================================
# Move all pdfs from "site" (the output dir of pdf exporting) to the scripts/pdf_export/pdfs
# ================================================================================================
find site -name "*.pdf" -exec mv {} scripts/pdf_export/pdfs \;
cd scripts/pdf_export/pdfs
# ================================================================================================
# Merge all pdfs into one single pdf file wrt the file name's order in chapters.txt
# ================================================================================================
# REMEMBER to put the chapters.txt into scripts/pdf_export/pdfs.
# Install: https://www.pdflabs.com/tools/pdftk-server/
# Install for M1 only: https://stackoverflow.com/a/60889993/6563277 to avoid the "pdftk: Bad CPU type in executable" on Mac
pdftk $(cat chapters.txt) cat output book.pdf
# ================================================================================================
# Add page numbers
# ================================================================================================
# Count pages https://stackoverflow.com/a/27132157/6563277
pageCount=$(pdftk book.pdf dump_data | grep "NumberOfPages" | cut -d":" -f2)
# Turn back to scripts/pdf_export
cd ..
# https://stackoverflow.com/a/30416992/6563277
# Create an overlay pdf file containing only page numbers
gs -o pagenumbers.pdf \
-sDEVICE=pdfwrite \
-g5950x8420 \
-c "/Helvetica findfont \
12 scalefont setfont \
1 1 ${pageCount} { \
/PageNo exch def \
450 20 moveto \
(Page ) show \
PageNo 3 string cvs \
show \
( of ${pageCount}) show \
showpage \
} for"
# Blend pagenumbers.pdf with the original pdf file
pdftk pdfs/book.pdf \
multistamp pagenumbers.pdf \
output final_book.pdf
然而,我们需要其他定制,如目录,书籍封面,作者部分,.以上所有步骤都只是合并和添加页名!有很多事要做。
https://stackoverflow.com/questions/74602739
复制相似问题