Prawn: 纯Ruby PDF 生成器程序库

Prawn 是由Gregory Brown开发的一个PDF生成器库。

Prawn can be installed from a pull from GitHub or, for those of us who are less adventurous, with a gem install prawn. Once installed, you can give it a quick test run:

  1. require 'prawn'
  2. Prawn::Document.generate("test.pdf"do
  3.   font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
  4.   text "this is a test " * 100
  5. end
Prawn comes with 11 typefaces.
如果要写入中文,可以使用它附带的字体gkai00mp.ttf,如下:
  1. Prawn::Document.generate("test.pdf"do
  2.    font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
  3.    text "这是一些中文"
  4. end
发现prawn对自动换行支持不完整,对于没有空格的情况,字符串会被安排在一行,而不会自动换行,如果中间有空格,才能自动换行,这样,对于中文就等於不支持自动换行了。
发布了46 篇原创文章 · 获赞 7 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/yangbo_hr/article/details/2768882