Created
October 12, 2013 08:39
-
-
Save redfield/6947503 to your computer and use it in GitHub Desktop.
Example python application for HyPDF
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 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this actually work or is it just a copy from heroku? I get error there is no job_id on line 11.