Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kool-dev/pdf
Micro-service for generating PDF files using Puppeteer with an Express API
https://github.com/kool-dev/pdf
docker docker-compose hacktoberfest node pdf puppeteer
Last synced: about 1 month ago
JSON representation
Micro-service for generating PDF files using Puppeteer with an Express API
- Host: GitHub
- URL: https://github.com/kool-dev/pdf
- Owner: kool-dev
- License: mit
- Created: 2020-09-05T12:33:35.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-09-25T15:39:53.000Z (over 1 year ago)
- Last Synced: 2024-03-15T09:07:45.519Z (10 months ago)
- Topics: docker, docker-compose, hacktoberfest, node, pdf, puppeteer
- Language: JavaScript
- Homepage:
- Size: 55.7 KB
- Stars: 19
- Watchers: 3
- Forks: 4
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# 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`](https://github.com/kool-dev/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:
```yml
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:
```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' => '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);
```* 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](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagepdfoptions)
## Getting started on developing locally this microservice
To get started with development locally (using [`kool`](https://github.com/kool-dev/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).