Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gip-inclusion/pdf-generator
Simple Node.js service to generate a PDF from an URL via Puppeteer
https://github.com/gip-inclusion/pdf-generator
Last synced: 4 months ago
JSON representation
Simple Node.js service to generate a PDF from an URL via Puppeteer
- Host: GitHub
- URL: https://github.com/gip-inclusion/pdf-generator
- Owner: gip-inclusion
- License: mit
- Created: 2021-09-08T15:09:52.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-28T16:04:27.000Z (9 months ago)
- Last Synced: 2024-04-13T18:27:03.377Z (8 months ago)
- Language: JavaScript
- Homepage: https://pdf.dora.inclusion.beta.gouv.fr
- Size: 263 KB
- Stars: 8
- Watchers: 8
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pdf-generator
This Express.js service will serve a PDF generated by a headless Chrome for 2 cases :
- from an arbitrary URL
- from a HTML string, provided in the body of a POST request# You can fork this repo to deploy your own PDF generator on Scalingo
There is a github action that will automatically deploy your app on Scalingo when you push on the `main` branch.
You will need to provide the following environment variables (in the github repo settings):
Variables :
APP_NAME: the name of the app on scalingo
REGION: the region of the app on scalingo
TARGZ_URL: the url of the tar.gz archive of the app to deploySecret :
SCALINGO_API_TOKEN: Which should be a token with the correct rights to deploy the app mentionned in the variables.## Usage
- To get a PDF named `monpdf.pdf` for the page `http://mon-service.com/mapage`, you have to set the `PAGE_URL_PREFIX` environment variable to `http://mon-service.com` and create a link like:
```
Download PDF
```- The /ping endpoint can be used as a heartbeat for the service. It will return the string "ok" and a 200 status code.
## Installation on Scalingo
- Create a Scalingo application linked to the repository.
as concurrency is not managed by this service, you should probably use S or M type containers. More information in the [nodejs-buildpack documentation](https://github.com/Scalingo/nodejs-buildpack#reasonable-defaults-for-concurrency)
- Setup the environnement variables:
- `STACK` should be set to `heroku-18`
- `PAGE_URL_PREFIX` should be set to the prefix of the URL you'll want to print (see `Usage`)
- `PDF_NAME` should be the default downloaded PDF filename; it will be used in case the `name` query var is missing## Future improvements
- The generated PDF should probably be cached