GitHub - kool-dev/pdf: Micro-service for generating PDF files using Puppeteer with an Express API (original) (raw)

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:

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' => '

This is my super kool HTML that I want to turn into an awesome PDF file!

This is a very silly example, but you get the idea of how powerful this is :)

', 'options' => json_encode([ 'format' => 'A4', 'printBackground' => false, ]), ], ])->getBody();

file_put_contents('path/to/my/super-kool.pdf', $pdf);

Getting started on developing locally this microservice

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

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:

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:

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).