First, you can start the container using the following command:
docker run -p 5000:5000 -v /path/to/local/templates:/data/templates -d xpublisher/weasyprint-rest:latest
Then you can use the following command to generate the report.pdf from the official WeasyPrint sample. You can find the files in tests/resources/report
.
curl \
-F 'html=@report.html' \
-F 'style=@report.css' \
-F "asset[]=@FiraSans-Bold.otf" \
-F "asset[]=@FiraSans-Italic.otf" \
-F "asset[]=@FiraSans-LightItalic.otf" \
-F "asset[]=@FiraSans-Light.otf" \
-F "asset[]=@FiraSans-Regular.otf" \
-F "asset[]=@heading.svg" \
-F "asset[]=@internal-links.svg" \
-F "asset[]=@multi-columns.svg" \
-F "asset[]=@report-cover.jpg" \
-F "asset[]=@style.svg" \
-F "asset[]=@table-content.svg" \
-F "asset[]=@thumbnail.png" \
-F "mode=png" \
http://localhost:5000/api/v1.0/print --output report.png
All configurations are set via environment variables.
Name | Default | Description |
---|---|---|
API_KEY |
"" |
Sets an API key that protects the /api/v1.0/print service from unauthorized access. The key is later compared with the header X_API_KEY . If no API_KEY is set, anyone can access the application. |
BLOCKED_URL_PATTERN |
"^.*$" |
Pattern to block certain URLs. These URLs are later not allowed within resources of the print service. These resources will be ignored. |
ALLOWED_URL_PATTERN |
"^$" |
Pattern to allow certain URLs. These URLs are later allowed within resources of the print service. |
MAX_UPLOAD_SIZE |
16777216 |
Maximum size of the upload. Default is 16MB |
Service to check if the service is still working properly.
GET /api/v1.0/health
Parameter | Type | Description |
---|---|---|
ping |
string |
Optional. Returns the ping in the field pong |
{
"status" : "OK",
"timestamp" : number,
"pong" : string?
}
The status
does always contain "OK".
The timestamp
does contain the current timestamp of the server in milliseconds.
The pong
is optional and will only be sent if the ping
parameter was passed. It contains the same value that ping
had.
Service to print a pdf or png
POST /api/v1.0/print
Parameter | Type | |
---|---|---|
html |
file or string |
Required. HTML file to convert. |
mode |
"pdf" or "png" |
Optional. Controls whether a PDF or PNG is rendered. The default is pdf . |
template |
string |
Optional. Template name for the use of predefined templates. |
style |
file or string |
Optional. Style to apply to the html . This should only be used if the CSS is not referenced in the html. If it is included via HTML link, it should be passed as asset . Only either style or style[] can be used. |
style[] |
file or file[] |
Optional. Multiple styles to apply to the html . This should only be used if the CSS is not referenced in the html. If it is included via HTML link, it should be passed as asset . Only either style or style[] can be used. |
asset[] |
file or file[] |
Optional. Assets which are referenced in the html. This can be images, CSS or fonts. The name must be 1:1 the same as used in the files. |
Raw output stream of with Content-Type
of application/pdf
or image/png
. For pdf
also the header Content-Disposition = 'inline;filename={HTML_FILE_NAME}.pdf
will be set.