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.
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:
docker-compose.yml file: pdf:
image: "kooldev/pdf:latest"
expose:
- 3000
kool start or docker-compose up -d), you can already start using the microservice to make PDFs! Example using PHP:use GuzzleHttp\Client;
$pdf = (new Client())->post('http://pdf_dev/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
To get started with development locally (using kool, of course!):
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.
Soon to be added wishes:
The API will provide endpoints for generating PDFs on the fly and returning them right away.
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.
Endpoint: GET /health
Returns the current status in JSON. Status code may be 200 (active) or 503 (not ready).
Content type
Image
Digest
Size
177.6 MB
Last updated
over 5 years ago
docker pull kooldev/pdf