Skip to content

Instantly share code, notes, and snippets.

@autocorr
Created May 9, 2014 03:10
Show Gist options
  • Save autocorr/a9aade73b73d51739733 to your computer and use it in GitHub Desktop.
Save autocorr/a9aade73b73d51739733 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# encoding: utf-8
from os.path import splitext
from argparse import ArgumentParser
from markdown import markdown
from weasyprint import HTML
parser = ArgumentParser(description='Write a markdown file to PDF.')
parser.add_argument('filen', metavar='FILE', type=str,
help='Markdown filename')
args = parser.parse_args()
filen = args.filen
basen, ext = splitext(filen)
with open(filen, 'r') as md, open(basen + '.pdf', 'w') as outf:
html = markdown(md.read())
HTML(string=html).write_pdf(basen + '.pdf')
print '-- Converting {0} to {1}.pdf'.format(filen, basen)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment