windows 下 gitbook 转 pdf 完整过程记录

自从EDK2的文档全部搬到gitbook后,就不能再下载了,查询资料非常麻烦。所以,只能想办法把gitbook转成pdf了。网上搜索一圈,发现要么是大神自己搞python,要么就使用calibre。 我选择了calibre. 按照网上的方法,踩了许多坑,最好终于弄好了。

操作系统: win10 64bit

1. 安装Node.js和calibre

   这两个软件安装都没有特别需要注意的地方,直接安装就好。

   Node.js: https://nodejs.org/dist/v12.18.4/node-v12.18.4-win-x64.zip

   calibre:https://calibre-ebook.com/download_windows

2. 安装 gitbook和gitbook-pdf

    npm install gitbook-cli

    npm install gitbook-pdf

3. 新建一目录gitbook,用来放置电子书,并从github下载需要的书, 以edk-ii-dsc-specification为例,从https://github.com/tianocore-docs/edk2-DscSpecification下载并解压到gitbook\DscSpecification

4. 开始转换pdf. 当前路径为gitbook

   A. gitbook pdf  DscSpecification DscSpecification.pdf

D:\gitbook>gitbook pdf DscSpecification DscSpecification.pdf
Installing GitBook 3.2.3
C:\Users\admin\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:287
      if (cb) cb.apply(this, arguments)
                 ^ 

这一步会先安装 Installing GitBook 3.2.3 并开始出错, “if (cb) cb.apply(this, arguments),cb.apply is not a function”。 因为懒,直接按照https://blog.csdn.net/weixin_42349568/article/details/108414441文章中的说法,把错误提示中的pollyfills.js文件中对statFix这个函数的调用和函数体全部注释掉。然后再执行完成GitBook 3.2.3的安装。

  //fs.stat = statFix(fs.stat)
  //fs.fstat = statFix(fs.fstat)
  //fs.lstat = statFix(fs.lstat)

/*
  function statFix (orig) {
    if (!orig) return orig
    // Older versions of Node erroneously returned signed integers for
    // uid + gid.
    return function (target, options, cb) {
      if (typeof options === 'function') {
        cb = options
        options = null
      }
      function callback (er, stats) {
        if (stats) {
          if (stats.uid < 0) stats.uid += 0x100000000
          if (stats.gid < 0) stats.gid += 0x100000000
        }
        if (cb) cb.apply(this, arguments)
      }
      return options ? orig.call(fs, target, options, callback)
        : orig.call(fs, target, callback)
    }
  }
*/

 

 B. 安装完GitBook 3.2.3后, 又提示Error: Couldn't locate plugins "puml", Run 'gitbook install' to install plugins from registry.

     因为这个edk2-DscSpecification的book.json文件中有用到这个插件。但我当前的路径是gitbook, 所以gitbook install 并没有解决问题,然后又是网上搜索,在一篇文章中提到是要安装book.json文件中的插件,于是切换到gitbook\DscSpecification,再次gitbook install, OK成功安装puml。

D:\gitbook\DscSpecification
`-- gitbook-plugin-puml@1.0.1
  `-- plantuml-encoder@1.2.3
    `-- pako@0.2.9

info: >> plugin "puml" installed with success

C. 再次执行gitbook pdf  DscSpecification DscSpecification.pdf

D:\gitbook>gitbook pdf DscSpecification DscSpecification.pdf
info: 8 plugins are installed
info: 7 explicitly listed
info: loading plugin "puml"... OK
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 38 pages
info: found 44 asset files
info: >> generation finished with success in 137.9s !
info: >> 1 file(s) generated

    终于生成了PDF, 但页面边距很大,于是又在网上搜索。在http://www.chengweiyang.cn/gitbook/customize/book.json.html这篇文章,找到可以在book.json中添加pdf相关配置。将边距都设置为0了,结果最终生成的PDF边距还是很大。算了,不奢求了。

  "pdf":{
    "pageNumbers":false,
    "fontSize":12,
    "paperSize":"a4",
    "margin":{
      "right":0,
      "left":0,
      "top":0,
      "bottom":0
    },
    "headerTemplate":null,
    "footerTemplate":null
  }

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值