Skip to content

Instantly share code, notes, and snippets.

@redfield
Created October 12, 2013 08:39
Show Gist options
  • Save redfield/6947503 to your computer and use it in GitHub Desktop.
Save redfield/6947503 to your computer and use it in GitHub Desktop.
Example python application for HyPDF
import requests # http://docs.python-requests.org/
from flask import Flask # http://flask.pocoo.org/
from flask import request
app = Flask(__name__)
# Make request to the HyPDF and upload the created file to the AWS S3 in an asynchronous style.
@app.route("/")
def index():
params = {'user': 'HYPDF_USER', 'password': 'HYPDF_PASSWORD', 'test': 'true', 'content': '<html><body>Test</body</html>', 'bucket': 'hypdf_test', 'key': 'hypdf_test.pdf', 'public': 'true', 'callback': 'http://yoursite.com/pdf_complete'}
r = requests.post('https://www.hypdf.com/htmltopdf', data=params)
return r.json()['job_id']
# Get response from the HyPDF
@app.route("/pdf_complete", methods=['POST'])
def print_pdf_data():
print 'job_id: ' + request.headers['hypdf-job-id']
print 'number of pages: ' + request.headers['hypdf-pages']
print 'url: ' + request.form['url']
return 'ok'
if __name__ == "__main__":
app.run()
@hgcsm
Copy link

hgcsm commented Aug 17, 2015

Does this actually work or is it just a copy from heroku? I get error there is no job_id on line 11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment