Skip to content

Instantly share code, notes, and snippets.

@luctraonmilin
Created September 27, 2013 19:45
Show Gist options
  • Save luctraonmilin/6734175 to your computer and use it in GitHub Desktop.
Save luctraonmilin/6734175 to your computer and use it in GitHub Desktop.
A simple script for downloading and converting online web pages to PDF files.
#
# = Mighty
#
# Convert Matt Might blog articles (or others by the way) to PDF format.
# This is useful for keeping as references and offline reading.
#
# Author:: Luc Traonmilin
# Date:: 2013-09-27
# License:: MIT
#
# Prerequisites:
#
# gem install pdfkit
# gem install wkhtmltopdf-binary
#
# Refer to https://github.com/pdfkit/pdfkit in case of any trouble with PDFKit.
#
# Command format:
#
# ruby mighty.rb <url> <file>
#
# Call it this way for example:
# ruby mighty.rb "http://matt.might.net/articles/discrete-math-and-code/" \
# "Might - Math to Code.pdf"
require 'pdfkit'
module Mighty
def self.retrieve(url, file)
begin
PDFKit.new(url).to_file file
rescue Exception => exception
puts exception
end
end
end
if __FILE__ == $0
Mighty::retrieve ARGV[0], ARGV[1]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment