Giter Club home page Giter Club logo

printer-webservice's Introduction

HTML to PDF Web Service

A WSGI web service for rendering HTML to PDF using wkhtmltopdf.

This work was inspired by https://github.com/openlabs/docker-wkhtmltopdf

TODO

  • Add the javascript client
  • Add a routing system
  • Use URL params to generate wkhtmltopdf cmd-line options
  • Add a cache system
  • Add a Procfile and .buildpack for a better Heroku compatibility
  • Add an auth system

Running the Service localy

  1. Install python3 (virtualenv recommendend)

  2. Install wkhtmltopdf here

  3. Install dependencies:

    pip3 install -r requirements.txt
    

    on mac change the line 82 on app.py from

    return ['/usr/bin/wkhtmltopdf.sh', '-q', '-d', '300', '-s', 'A4', '-', '-']
    

    to

    return ['wkhtmltopdf', '-q', '-d', '300', '-s', 'A4', '-', '-']
    
  4. Run server:

    python3 app.py
    

The development server listens on port 5000.

Using the Service

The web service accepts an HTML document as the "html" and "filename" parameter in the body of a URL-encoded web form POST request and responds with the rendered PDF. For example:

curl -d html='<p>Hello world!</p>' -d filename='test.pdf' http://localhost:5000 > output.pdf

An HTML file can also be included as multipart form data, for example:

cat sample.html | curl -F html=@- http://localhost:5000 > output.pdf

Running as Docker Container

To run the service as a Docker container with compose:

docker-compose up -d

Or build it and run it manually:

docker build -t printer-webservice .
docker run -p 5000:8080 printer-webservice

printer-webservice's People

Contributors

denniszelada avatar dependabot[bot] avatar gabklein avatar pdelsol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

printer-webservice's Issues

use updated URL for wkhtmltopdf downloads

Hello,

wkhtmltopdf has moved the downloads provider from SourceForge to gna.org. As mentioned in the linked message, all earlier downloads have been removed from SourceForge and you are strongly advised to migrate to the new URLs. The following files in your repository will need to be updated:

  • Dockerfile

It is recommended to either subscribe to the mailing list or Twitter feed to receive updates on new releases and further changes.

Thanks,
wkhtmltopdf maintainer

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.