Code Monkey home page Code Monkey logo

pdf's Introduction

PDF microservice

PDF generation micro-service. Super easy to add on kool and docker-compose based environments, for generating PDFs from any URLs or given HTML content.

Getting started using this microservice in your project

If you use Docker Compose (hopefully with kool to make things simpler) you can get PDF generation on your project with a few simple steps:

  • Add the service to your docker-compose.yml file:
  pdf:
    image: "kooldev/pdf:1.0"
    ports:
      - "3000:3000"
  • After starting the service containers (with either kool start or docker-compose up -d), you can already start using the microservice to make PDFs! Example using PHP:
use GuzzleHttp\Client;

// the hostname is the docker-compose service name, or an alias you add to your docker network
$pdf = (new Client())->post('http://pdf:3000/from-html', [
    'form_params' => [
        'html' => '<h1>This is my super kool HTML that I want to turn into an awesome PDF file!</h1> <p> This is a very silly example, but you get the idea of how powerful this is <b>:)</b> </p>',
        'options' => json_encode([
            'format' => 'A4',
            'printBackground' => false,
        ]),
    ],
])->getBody();

file_put_contents('path/to/my/super-kool.pdf', $pdf);
  • Important to notice, the code above assumes you are running it from within another container in the same Docker Compose application so the pdf domain resolves to our microservice.

  • The options should be a json data type

  • You can see all these options in puppeteer docs

Getting started on developing locally this microservice

To get started with development locally (using kool, of course!):

  • Fork the repo.
  • Clone the fork.
  • kool run yarn install - this will install dependencies.
  • kool start - will get up the API on localhost:3000.
  • docker-compose logs -f - tails the API logs.

In order to manage dependencies and run commands, please remind of using kool run yarn to stick with one single yarn version.

Roadmap

Soon to be added wishes:

  • Parameters to better control Javascript execution/wait condition.
  • Conversion to images also.
  • Got some kool feature you are not seeing? Please open a ticket to suggest it!

API

The API will provide endpoints for generating PDFs on the fly and returning them right away.

From an URL

Endpoint: GET /from-url?url=

Parameters:

  • url: URL of the page we want to convert to PDF.

Returns the rendered PDF from the provided URL, or a JSON with an error message and status.

Health status

Endpoint: GET /health

Returns the current status in JSON. Status code may be 200 (active) or 503 (not ready).

pdf's People

Contributors

b-lopes avatar danielsuguimoto avatar dbpolito avatar fabriciojs avatar leandroncbrito avatar matheuswsantos avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

pdf's Issues

Outdated Chromium

This Dockerfile is based on kooldev/puppeteer:latest (published 2 years ago), which currently seems to contain Chromium 81.0.4044.113, with the current version being 93.0.4577.82.

There seems to be a 1.0-tagged image of kooldev/puppeteer, which seems newer (published a month ago).

It'd be great if kooldev/puppeteer:latest got rebuilt/republished, or even better if kool-dev/pdf switched to using the 1.0 tag (or some other, newer, published tag) of kooldev/puppeteer.

Improve documentation

We have to document both usage (how to add and use in a project) as well as documentation for how to develop/test locally (adding a Postman collection would be nice).

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.