Skip to content

Instantly share code, notes, and snippets.

@geelen
Created March 4, 2009 06:42
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 geelen/73748 to your computer and use it in GitHub Desktop.
Save geelen/73748 to your computer and use it in GitHub Desktop.
desc "Grab the html files and pdf-ize them through safari"
task :html_to_pdf => ['main.html', 'scalpel.html'] do
require 'rbosa'
run "rm ~/Desktop/cups-pdf/*", "Cleaning ~/Desktop/cups-pdf"
app = OSA.app('Safari')
files.each { |file|
app.make OSA::Safari::Document, :with_properties => { :url => "file://localhost/Users/glen/work/boost-doc/#{file}.html" }
sleep 1 while (app.do_javascript("document.readyState", app.documents[0]) != "complete")
app.print app.documents[0], :print_dialog => false
output_file = nil
sleep 1 while (output_file = Dir[ENV["HOME"] + "/Desktop/cups-pdf/*"].first).nil?
app.close app.documents[0]
run "mv #{output_file} #{file}.html.pdf", "Moving file to #{file}.html.pdf"
run "open #{file}.html.pdf", "Opening pdf"
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment