Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - accept content to render pdf by url #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@ def home():
@app.route('/pdf', methods=['POST'])
def generate():
name = request.args.get('filename', 'unnamed.pdf')
app.logger.info('POST /pdf?filename=%s' % name)
#print ( request.get_data() )
html = HTML(string=request.get_data())
type = request.args.get('type', 'string')
app.logger.info('POST /pdf?filename=%s&type=%s' % (name, type))
html = None
if type == 'string':
html = HTML(string=request.get_data())
elif type == 'url':
url_args = {'encoding': request.args.get('encoding', None),
'media_type': request.args.get('media_type', 'print'),
'base_url': request.args.get('base_url', None)}
html = HTML(url=request.get_data().decode('UTF-8'), **url_args)
pdf = html.write_pdf()
response = make_response(pdf)
response.headers['Content-Type'] = 'application/pdf'
Expand Down