Giter Site home page Giter Site logo

ciricihq / wkhtmltopdf-flask-aas Goto Github PK

View Code? Open in Web Editor NEW
16.0 16.0 18.0 59 KB

Wkhtmltopdf Flask As a Service

License: GNU General Public License v3.0

Python 100.00%
docker-container microservice pdf pdf-generation pdfkit python wkhtmltopdf wkhtmltopdf-flask

wkhtmltopdf-flask-aas's People

Contributors

elboletaire avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

wkhtmltopdf-flask-aas's Issues

Render react.js pages

Current result: blank or black pages instead expected content. May be need wait few seconds (for page loading and script execution) before rendering?

Unicode encode error

I got the following UnicodeEncodeError:

[2017-03-10 13:21:05,861] ERROR in app: Exception on /pdf [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "app.py", line 15, in pdf
    doc = handle_request(config)
  File "app.py", line 44, in handle_request
    pdf = pdfkit.from_string(str(request.form['html']), output_path=False, configuration=config, options=options)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)

This is how I did the request:

response = requests.post(
    'http://localhost:5000/pdf', data={
    'html': 'áááááá',
    'options': {'encoding': 'UTF-8'},
})

Any advices?

Filter health checks in log

When you configure health checks in docker/kubernetes/whatever the log gets "spammed" with these requests.
It would be neat to filter that from the requestlogging.

I don't know the stack, so I have no clue where to start.
I was able to add a simple health endpoint by adding

@app.route("/health", methods=['GET'])
def health():
return Response("{healthy: 'true'}", mimetype='application/json')

to the app.py, but I don't know where to skip the access-log for the endpoint.

BTY: a health endpoint is a good idea, even docker itself supports that now

pages

Hi! I love your work. I am trying to make page numbers alternately appear at the bottom left for odd pages and bottom right for even pages. Is there a way to do that?
What I have so far is this...

wkhtmltopdf_path = 'C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=wkhtmltopdf_path)
options = {
    'footer-center': '~ [page] of [topage] ~',

'unicode' is not defined with alpine

I got the following error when generating a PDF from HTML with the "alpine" tag:

[2022-05-20 08:10:41,195] ERROR in app: Exception on /pdf [POST]
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "app.py", line 15, in pdf
doc = handle_request(config)
File "app.py", line 44, in handle_request
pdf = pdfkit.from_string(unicode(request.form['html']), output_path=False, configuration=config, options=options)
NameError: name 'unicode' is not defined

I tried with the docker image with "latest" tag based on Debian, it works as expected.

How can I update the dockerfile or app.py to make it works also on alpine?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.