Here is the python script I used to install everything (I have a directory 'scripts' that contains all python stuff):
<pre>
import urllib
import tarfile
from zipfile import ZipFile
import shutil
import console
import os
import editor
from os.path import expanduser
os.chdir(expanduser('~/Documents/'))
url = 'http://www.reportlab.com/ftp/reportlab-2.7.tar.gz'
fname='reportlab-2.7'
sname='src/reportlab'
dname='scripts/reportlab'
print 'Downloading '+dname+'...'
urllib.urlretrieve(url, fname+'.tar.gz')
print 'Extracting...'
t = tarfile.open(fname+'.tar.gz')
t.extractall()
if os.path.isdir(dname):
shutil.rmtree(dname)
shutil.move(fname+'/'+sname, dname)
print 'Cleaning up...'
shutil.rmtree(fname)
os.remove(fname+'.tar.gz')
url='http://pybrary.net/pyPdf/pyPdf-1.13.tar.gz'
fname='pyPdf-1.13'
sname='pyPdf'
dname='scripts/pyPdf'
print 'Downloading '+dname+'...'
urllib.urlretrieve(url, fname+'.tar.gz')
print 'Extracting...'
t = tarfile.open(fname+'.tar.gz')
t.extractall()
if os.path.isdir(dname):
shutil.rmtree(dname)
shutil.move(fname+'/'+sname, dname)
print 'Cleaning up...'
shutil.rmtree(fname)
os.remove(fname+'.tar.gz')
url = 'https://github.com/html5lib/html5lib-python/archive/master.zip'
fname='html5lib-python-master'
sname='html5lib'
dname='scripts/html5lib'
print 'Downloading '+dname+'...'
urllib.urlretrieve(url, fname+'.zip')
print 'Extracting...'
with ZipFile(fname+'.zip', 'r') as z:
z.extractall()
if os.path.isdir(dname):
shutil.rmtree(dname)
shutil.move(fname+'/'+sname, dname)
print 'Cleaning up...'
shutil.rmtree(fname)
os.remove(fname+'.zip')
url='https://github.com/chrisglass/xhtml2pdf/archive/master.zip'
fname='xhtml2pdf-master'
sname='xhtml2pdf'
dname='scripts/xhtml2pdf'
print 'Downloading '+dname+'...'
urllib.urlretrieve(url, fname+'.zip')
print 'Extracting...'
with ZipFile(fname+'.zip', 'r') as z:
z.extractall()
if os.path.isdir(dname):
shutil.rmtree(dname)
shutil.move(fname+'/'+sname, dname)
print 'Cleaning up...'
shutil.rmtree(fname)
os.remove(fname+'.zip')
url='http://www.reportlab.com/ftp/pfbfer-20070710.zip'
fname='scripts/xhtml2pdf/fonts/pfbfer-20070710'
sname='pfbfer-20070710'
dname='scripts/xhtml2pdf/fonts'
if os.path.isdir(dname):
shutil.rmtree(dname)
os.mkdir(dname)
print 'Downloading '+sname+'...'
urllib.urlretrieve(url, fname+'.zip')
print 'Extracting...'
dr=os.getcwd()
os.chdir(dname)
with ZipFile(sname+'.zip', 'r') as z:
z.extractall()
os.chdir(dr)
print 'Cleaning up...'
os.remove(fname+'.zip')
editor.reload_files()
print 'Done'
</pre>
Then the workflow contains a 'Document Text' step, followed by a 'Convert Markdown to HTML' step, followed by the following 'Run Python Script' step:
<pre>
#coding: utf-8
import sys
from os.path import expanduser
if not(expanduser('~/Documents/scripts') in sys.path):
sys.path.append(expanduser('~/Documents/scripts'))
import workflow
import os.path
import editor
import xhtml2pdf.pisa as pisa
import StringIO
from urllib import unquote
pisa.showLogging()
def link_callback(uri,rel):
if not(uri.startswith('/')):
return dir+'/'+unquote(uri)
return unquote(uri)
action_in = workflow.get_input()
pre='<html>\n<head>\n<meta charset="utf-8"/>\n<style>\n p {font-size:12pt}\n</style>\n</head>\n\n<body>\n'
post='\n</body>\n</html>'
inp=StringIO.StringIO(pre+action_in.encode('ascii', 'xmlcharrefreplace')+post)
p = editor.get_path()
dir = os.path.split(p)[0]
f = os.path.split(p)[1]
fn= os.path.splitext(f)[0]
fl = file(dir+'/'+fn+".pdf", "w+b")
print('processing '+p)
pdf = pisa.CreatePDF(inp,fl,dir,link_callback=link_callback)
fl.close()
if pdf.err!=0:
print(pdf.err)
else:
print('done!')
</pre>