Sign inSign up

labun/pdf-generation-service

By labun

Updated over 8 years ago

PDF Generation Service based on PhantomJS.

Image
2

50K+

labun/pdf-generation-service repository overview

gen-pdf

service to generate pdf from html using phantomjs, credit goes to node-html-pdf package.

Docker Hub

How does it work
Run locally
  $ npm install
  $ npm test
  $ npm start

  $ HTML=$(base64 -w 0 charts.html) && curl -o chart.pdf -X POST -H "Content-Type: application/json" -d "{\"html\":\"$HTML\"}" "http://localhost:3000/"
  # you could provide custom configuration to generate the pdf look Next javascript Example
  # all configuration from https://github.com/marcbachmann/node-html-pdf#options is possible configuration
  # prometheus metrics
  $ curl "http://localhost:3000/metrics"
  # http_requests_total{code="400",method="post"} 1
Example
    let config = {
      orientation: 'landscape',
      border: {
        top: '19mm'
      },
      footer: {
        height: '28mm',
        contents: {
          '2': 'Second page',
          'first': 'Cover page',
          'default': '<span style="color: #444;">{{page}}</span>/<span>{{pages}}</span>',
          'last': 'Last Page'
        }
      }
    };
    let settings = {
      "url": "http://localhost:3000/",
      "method": "POST",
      "headers": {
        "content-type": "application/x-www-form-urlencoded"
      },
      "data": {
        "html": "<div>hi</div>",
        "config": JSON.stringify(config)
      }
    };

    $.ajax(settings).done(function (response) {
      console.log(response);
    });
Build and run with docker
  $ docker build -t waleedsamy/gen-pdf . # or docker pull waleedsamy/gen-pdf
  $ docker run -d -e LOG_FORMAT=pretty -p 3000:3000 waleedsamy/gen-pdf
Kubernetes friendly
  # prometheus will scrape pdfgenerator service automatically
  $ kubect create -f ./deploy/

Tag summary

Content type

Image

Digest

Size

391.8 MB

Last updated

over 8 years ago

docker pull labun/pdf-generation-service