参考了其他网页内容,网页上说:

 

输出为PDF文件,需要先安装gitbook pdf

$ npm install gitbook-pdf -g

如果在安装gitbook-pdf时,觉得下载phantomjs包太慢的话,你可以到phantomjs的官方网站上去下载。

http://phantomjs.org/

这个包的安装方式,参考其官网的说明文档。

然后,用下面的命令就可以生成PDF文件了。

$ gitbook pdf {book_name}

如果,你已经在编写的gitbook当前目录,也可以使用相对路径。

$ gitbook pdf .

然后,你就会发现,你的目录中多了一个名为book.pdf的文件。

 

我是这么干的

复制代码
 1 [root@fedora phantomjs]# npm install  gitbook-pdf  -registry https://registry.npmmirror.com                                                            
 2 
 3 npm WARN deprecated eslint@1.10.3: This version is no longer supported. Please see https://eslint.org/version-support for other options.
 4 npm ERR! code 1
 5 npm ERR! path /root/node_modules/.store/phantomjs@2.1.7/node_modules/phantomjs/node_modules/phantomjs
 6 npm ERR! command failed
 7 npm ERR! command sh -c -- node install.js
 8 npm ERR! Downloading http://cdn.bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2
 9 npm ERR! Saving to /tmp/phantomjs/phantomjs-1.9.7-linux-x86_64.tar.bz2
10 npm ERR! Receiving...
11 npm ERR! Error requesting archive.
12 npm ERR! Status: 301
13 npm ERR! Request options: {
14 npm ERR!   "protocol": "http:",
15 npm ERR!   "slashes": true,
16 npm ERR!   "auth": null,
17 npm ERR!   "host": "cdn.bitbucket.org",
18 npm ERR!   "port": null,
19 npm ERR!   "hostname": "cdn.bitbucket.org",
20 npm ERR!   "hash": null,
21 npm ERR!   "search": null,
22 npm ERR!   "query": null,
23 npm ERR!   "pathname": "/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2",
24 npm ERR!   "path": "/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2",
25 npm ERR!   "href": "http://cdn.bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2"
26 npm ERR! }
27 npm ERR! Response headers: {
28 ...
复制代码

第8行有需要下载的软件包和url,后来显示的是说未下载成功。现在手动下载该包,并移动到/tmp/phantomjs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@fedora ~]# npm install  gitbook-pdf  -registry https://registry.npmmirror.com                                                                   
npm WARN deprecated osenv@0.0.3: This package is no longer supported.                                                                                 
npm WARN deprecated ini@1.1.0: Please update to ini >=1.3.6 to avoid a prototype pollution issue                                                      
npm WARN deprecated rimraf@2.2.8: Rimraf versions prior to v4 are no longer supported                                                                 
npm WARN deprecated npmconf@0.0.24: this package has been reintegrated into npm and is now out of date with respect to npm                            
npm WARN deprecated mkdirp@0.3.5: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has change
d to use Promises in 1.x.)                                                                                                                            
npm WARN deprecated mkdirp@0.3.5: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has change
d to use Promises in 1.x.)                                                                                                                            
                                                                                                                                                        
added 17 packages, and changed 1 package in 4s                                                                                                        
 
2 packages are looking for funding
  run `npm fund` for details