记将github中Asciidoc文档格式项目导出pdf的一次实践

来源:互联网 发布:linux ant是什么 编辑:程序博客网 时间:2024/05/21 03:16

首先将github中的Asciidoc项目下载到电脑, 为保留博主操作时的项目源码,这里不要脸的拿出自己fork的一份git官方文档项目: https://github.com/yeqizhang/progit2-zh


下载好后解压,根路径下有个Gemfile的文件,这里需要使用ruby语言来进行操作。

github项目,必须要看的文件 README ,里边写道:

$ bundle install$ asciidoctor-pdf-cjk-kai_gen_gothic-install$ bundle exec rake book:build
只要使用这个三个命令,就可以将  HTML、Epub、Mobi、PDF 四种格式的文件导出来。

不过,过程却没这么简单顺畅。。。这也和博主第一次接触到ruby这语言有关系吧。


一、安装 ruby ,以及执行 bundle install 

首先博主考虑的是在window系统上操作,然后下载了Jruby,不过耗费了几个小时,中间gem插件包时各种错误,解决不了。罢了还是用linux吧,博主有个树莓派,就远程在里边弄,首先楼主傻傻地又装了Jruby,然后想起之前有用ruby脚本时安装过ruby的。于是切换到progit2-zh路径下,执行bundle install(没有bundle就 gem install bundle) ,中间似乎很顺利,到gem某个包时提示我的ruby版本太低了需要2.0后的版本,于是又安装rvm来管理ruby,  下载好高版本ruby后,由于我的树莓派cpu不行,中间编译了大半个小时吧。

接着继续bundle install (遇见错误,尝试处理后,继续执行这条命令),中间还是会有gem安装失败的情况,注意:

bundle是从Gemfile和Gemfile.lock找要gem的包自动去下载的,Gemfile.lock设置了要安装的插件以及版本, 如果安装失败 ,

可以先去https://rubygems.org/gems 搜这个插件,把Gemfile.lock中这个插件的版本设置的高一点,这里贴一份博主修改后的Gemfile.lock的内容:

GEM  remote: https://rubygems.org/  specs:    Ascii85 (1.0.2)    addressable (2.3.8)    afm (0.2.2)    asciidoctor (1.5.0)    asciidoctor-epub3 (1.0.0.alpha.2)      asciidoctor (>= 1.5.0, < 1.6.0)      gepub (~> 0.6.9.2)      thread_safe (~> 0.3.4)    asciidoctor-pdf (1.5.0.alpha.8)      asciidoctor (~> 1.5.0)      prawn (>= 1.3.0, < 3.0.0)      prawn-icon (= 0.6.4)      prawn-svg (= 0.20.0)      prawn-table (= 0.2.1)      prawn-templates (= 0.0.3)      safe_yaml (= 1.0.4)      thread_safe (= 0.3.4)      treetop (= 1.5.3)    asciidoctor-pdf-cjk (0.1.2)      asciidoctor-pdf (~> 1.5.0.alpha.8)    asciidoctor-pdf-cjk-kai_gen_gothic (0.1.1)      asciidoctor-pdf-cjk (~> 0.1.2)    awesome_print (1.2.0)    coderay (1.1.0)    css_parser (1.3.7)      addressable    epubcheck (3.0.1)    gepub (0.6.9.2)      nokogiri (~> 1.6.1)      rubyzip (>= 1.1.1)    hashery (2.1.1)    json (2.0.4)    kindlegen (2.9.4)    mini_portile (0.6.0)    multi_json (1.12.1)    nokogiri (1.6.3.1)      mini_portile (= 0.6.0)    pdf-core (0.6.0)    pdf-reader (1.3.3)      Ascii85 (~> 1.0.0)      afm (~> 0.2.0)      hashery (~> 2.0)      ruby-rc4      ttfunk    polyglot (0.3.5)    prawn (2.0.2)      pdf-core (~> 0.6.0)      ttfunk (~> 1.4.0)    prawn-icon (0.6.4)      prawn (>= 1.1.0, < 3.0.0)    prawn-svg (0.20.0)      css_parser (~> 1.3)      prawn (>= 0.8.4, < 3)    prawn-table (0.2.1)    prawn-templates (0.0.3)      pdf-reader (~> 1.3)      prawn (>= 0.15.0)    pygments.rb (1.1.2)      multi_json (>= 1.0.0)    rake (10.3.2)    ruby-rc4 (0.1.5)    rubyzip (1.1.6)    safe_yaml (1.0.4)    thread_safe (0.3.4)    treetop (1.5.3)      polyglot (~> 0.3)    ttfunk (1.4.0)PLATFORMS  rubyDEPENDENCIES  asciidoctor (= 1.5.0)  asciidoctor-epub3 (= 1.0.0.alpha.2)  asciidoctor-pdf (= 1.5.0.alpha.8)  asciidoctor-pdf-cjk-kai_gen_gothic (~> 0.1.1)  awesome_print  coderay  epubcheck  json  kindlegen  pygments.rb  rake  thread_safeBUNDLED WITH   1.15.3

下面是博主所有插件装好后再次执行 bundle install 的截图:



二、执行asciidoctor-pdf-cjk-kai_gen_gothic-install 下载语言字体包

这一步因为国内网络环境的问题尝试很多次都没有下载下来,后来找到这个插件的github项目,直接在发行版里找到了下载,地址为https://github.com/chloerei/asciidoctor-pdf-cjk-kai_gen_gothic/releases ,下载好以后放入 asciidoctor-pdf-cjk-kai_gen_gothic插件的子文件夹data/fonts文件夹里。


三、执行bundle exec rake book:build  ,大功告成。


附中英文下载链接

英文: 我上传失败了。。网上很多的。

中文(需要积分,也可以私信我邮箱发给你):http://download.csdn.net/download/yqztgc123/9937376