Created
December 22, 2010 17:49
-
-
Save axiak/751825 to your computer and use it in GitHub Desktop.
convert a url 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 tempfile | |
import os | |
from subprocess import Popen, PIPE | |
# Prereqs: | |
# apt-get install html2ps ghostscript | |
def convert_to_pdf(html): | |
" Convert some html to a pdf. " | |
ps_process = Popen("html2ps", stdin=PIPE, stdout=PIPE, shell=True) | |
ps_content = ps_process.communicate(html)[0] | |
pdf_process = Popen('ps2pdf - -', stdin=PIPE, stdout=PIPE, shell=True) | |
return pdf_process.communicate(ps_content)[0] | |
def download_url(url): | |
import urllib | |
return urllib.urlopen(url).read() | |
def main(): | |
import sys | |
print convert_to_pdf(download_url(sys.argv[-1])) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment