This Express.js service generates PDFs from two sources:
- An arbitrary URL via the
/printendpoint - An HTML string provided in the request body via the
/generateendpoint
You can deploy your own PDF generator on Scalingo by forking this repository.
A GitHub action automatically deploys the application to Scalingo when you push to the main branch.
You will need to provide the following environment variables (in the GitHub repository settings):
Variables:
APP_NAME: the name of the app on ScalingoREGION: the region of the app on ScalingoTARGZ_URL: the URL of the tar.gz archive of the app to deploy
Secret:
SCALINGO_API_TOKEN: a token with the appropriate rights to deploy the app mentioned in the variables
- 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
- Set up the environment variables:
API_KEY: API key to secure the endpointsPORT: port on which the server will listen
Generates a PDF from a URL. The complete URL must be provided in the url parameter.
Query parameters:
url: the complete URL of the page to convert to PDF (required, must be URL-encoded)name: the name of the downloaded PDF file (required)marginTop: top margin (default: "1cm")marginRight: right margin (default: "1cm")marginBottom: bottom margin (default: "1cm")marginLeft: left margin (default: "1cm")
Example:
https://<thisservicehostname>/print?url=https%3A%2F%2Fexample.com%2Fpage&name=document.pdf&marginTop=2cm&marginRight=1.5cm
Note: The URL must be properly URL-encoded. In the example above, https://example.com/page is encoded as https%3A%2F%2Fexample.com%2Fpage.
Generates a PDF from an HTML string.
Request body (JSON):
{
"htmlContent": "<html>...</html>",
"marginTop": "2cm",
"marginRight": "1.5cm",
"marginBottom": "2cm",
"marginLeft": "1.5cm"
}Query parameters:
request_id: request identifier (optional, automatically generated if not provided)
Default margins for this endpoint:
marginTop: "2.5cm"marginRight: "1.5cm"marginBottom: "2.5cm"marginLeft: "1.5cm"
Used as a heartbeat for the service. Returns the string "ok" with a 200 status code.
All endpoints are protected by an API key that must be provided in the Authorization header of each request.
- The generated PDF should probably be cached