Skip to content

Instantly share code, notes, and snippets.

@empr
Created September 9, 2012 11:46
Show Gist options
  • Save empr/3683946 to your computer and use it in GitHub Desktop.
Save empr/3683946 to your computer and use it in GitHub Desktop.
Make pdf from url
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
require 'pdfkit'
if __FILE__ == $0
url = ARGV[0]
doc = Nokogiri::HTML(open(url))
filename = doc.title ? "#{doc.title.strip}.pdf" : "#{url}.pdf"
puts filename
pdf = PDFKit.new(url)
pdf.to_pdf
pdf.to_file(filename)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment