Created
December 6, 2013 21:42
-
-
Save shahidhk/7832604 to your computer and use it in GitHub Desktop.
From http://pdfcrowd.com/web-html-to-pdf-python/
Convert html to pdf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pdfcrowd | |
| try: | |
| # create an API client instance | |
| client = pdfcrowd.Client("username", "apikey") | |
| # convert a web page and store the generated PDF into a pdf variable | |
| pdf = client.convertURI('http://www.google.com') | |
| # convert an HTML string and save the result to a file | |
| output_file = open('html.pdf', 'wb') | |
| html="<head></head><body>My HTML Layout</body>" | |
| client.convertHtml(html, output_file) | |
| output_file.close() | |
| # convert an HTML file | |
| output_file = open('file.pdf', 'wb') | |
| client.convertFile('/path/to/MyLayout.html', output_file) | |
| output_file.close() | |
| except pdfcrowd.Error, why: | |
| print 'Failed:', why |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment