Skip to content

Instantly share code, notes, and snippets.

@beepony
Created March 23, 2017 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beepony/2379c18399e116c1b8ed0013f08e45d8 to your computer and use it in GitHub Desktop.
Save beepony/2379c18399e116c1b8ed0013f08e45d8 to your computer and use it in GitHub Desktop.
使用 Ruby 把 HTML 转成 PDF 输出
#! /usr/bin/ruby -w
# test html to pdf lib
require 'pdfkit'
# 从 URL 转换成 PDF
kit = PDFKit.new('https://techs.b0.upaiyun.com/article/%E9%98%BF%E9%87%8C%E4%BA%91%E5%AE%89%E5%85%A8%E7%BB%84%E5%92%8C%E4%BA%91%E7%9B%BE%E8%AE%BE%E7%BD%AE.html')
# 从本地 HTML 文件转换成 PDF
kit = PDFKit.new(File.new('./pdf.html'))
# 以文件的方式输出
file = kit.to_file('./lala.pdf')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment