Linux下Gitbook生成pdf及中文问题的解决

Linux下Gitbook生成pdf

sudo -v && wget -nv -O- https://download.calibre-ebook.com/linux-installer.py | sudo python -c "import sys; main=lambda:sys.stderr.write('Download failed\n'); exec(sys.stdin.read()); main()"
  • 配置book.json
{
    "title": "Cloudroom SDK Refference",
    "description": "云屋视频SDK参考文档",
    "author": "HeDonghai",
    "language": "zh-hans",
    "styles": {
        "website": "style.css"
    },
    "plugins": [
        "-lunr",
        "-search",
        "-livereload",
        "-sharing",
        "book-summary-scroll-position-saver",
        "expandable-chapters",
        "search-plus",
        "splitter",
        "tbfed-pagefooter",
        "back-to-top-button",
        "yahei",
        "katex",
        "theme-api",
        "theme-comscore"
    ],
    "pluginsConfig": {
        "expandable-chapters": {},
        "theme-api": { "theme": "light" },
        "tbfed-pagefooter": {
            "copyright": "© HeDonghai",
            "modify_label": "文件修订时间:",
            "modify_format": "YYYY-MM-DD HH:mm:ss"
        },
        "fontSettings": {
            "theme": "white",
            "family": "msyh",
            "size": 2
          }
    },
    "pdf": {
        "toc": true,
        "pageNumbers": true,
        "fontSize": 18,
        "paperSize": "a3",
        "margin": {
          "right": 30,
          "left": 30,
          "top": 30,
          "bottom": 50
        }
      }
}
//pdf 配置下的toc貌似没有生效
  • 安装Gitbook插件

cd 进入存放book.json的Linux目录下,然后执行命令

gitbook install
  • 生成pdf
    在markdown文件目录下执行下面的命令会自动book.pdf文件
gitbook pdf
  • pdf文档内中文不显示或中文乱码

原因是中文字体未支持,可手动配置支持,操作如下:
1. 在插件配置中使用”yahei”(雅黑字体)并配置fontSettings
2. 手动从windows系统的Fonts目录下复制msyh.ttc文件或msyh.ttf文件上传到Linux的/usr/share/fonts/truetype目录下
3. 重新生成pdf即可

猜你喜欢

转载自blog.csdn.net/hsshh1988/article/details/78730654
今日推荐