jmquintana79
1/26/2016 - 2:48 PM

Markdown file to pdf

Markdown file to pdf

from markdown import markdown
import pdfkit


def md2pdf(input_path,output_path):
  try:
    with open(input_path, 'r') as f:
        html_text = markdown(f.read(), output_format='html4')
        
    pdfkit.from_string(html_text, output_path)
  except Exception,e:
    print 'ERROR: %s'%e
  
  return None


if __name__ == "__main__":
  input_path = 'input_folder/input_filename.md'
  output_path =  'output_folder/output_filename.pdf'
  # execute function
  md2pdf(input_path,output_path)