I just posted a PDF version of the Script Debugger 7 Help Book and I thought some may be curious how this was created. Here’s how I did it using open source tools:
-
Download and install the wkhtmptopdf package. This creates the
wkhtmltopdf
command which I used to convert HTML to PDF. -
You need to collect the paths of all the HTML files in the Script Debugger 7 help book. Once you have these, you can use the
wkhtmltopdf
command to generate a single, hyperlinked, PDF file.The trick to getting all the HTML files in the right order is to follow the Next links on each page of the Help Book to identify each HTML file and its order. I used this crude Ruby script to do this (named makeHelp.rb):
#!/usr/bin/ruby
$cmd = "wkhtmltopdf "
def processFile(filename)
File.readlines(filename).each { |line|
if line =~ /href="([^"]*)">.*trueNext/
dir = File.dirname(filename)
path = File.absolute_path(File.join(dir, $1))
$cmd << "#{path} "
processFile(path)
end
}
end
ARGV.each { |filename|
$cmd << "#{filename} "
processFile(filename)
}
$cmd << "OUTPUT.pdf"
puts `#{$cmd}`
puts `open OUTPUT.pdf`
This script generates an OUTPUT.pdf
file in the current directory. If you have Script Debugger 7 installed in the /Applications
folder, then the command to invoke this script looks like this:
ruby makeHelp.rb -- /Applications/Script\ Debugger.app/Contents/Resources/English.lproj/sd7help/index.html
P.S. I have to point out that I used CodeRunner 2 to create this script. I usually live in the fantastic BBEdit for text editing, but Code Runner made this so simple to do. For US$15, its a bargain.