First, you can start the container using the following command:
docker run -p 5000:5000 -v /path/to/local/dir:/data -d ronisaha/easy-pdf-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 '[email protected]' \
-H X-API-KEY:key \
-F '[email protected]' \
-F "asset[][email protected]" \
-F "asset[][email protected]" \
-F "asset[][email protected]" \
-F "asset[][email protected]" \
-F "asset[][email protected]" \
-F "asset[][email protected]" \
-F "asset[][email protected]" \
-F "asset[][email protected]" \
-F "asset[][email protected]" \
-F "asset[][email protected]" \
-F "asset[][email protected]" \
-F "asset[][email protected]" \
http://localhost:5000/api/v1.0/print --output report.pdf
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 |
104857600 |
Maximum size of the upload. Default is 100MB |
UPLOAD_EXTENSIONS |
.png,.jpg,.jpeg,.tiff,.bmp,.gif,.pdf |
Allowed extensions while using merge endpoint |
TEMPLATE_DIRECTORY |
/data/templates |
Base path for templates |
REPORT_DIRECTORY |
/data/reports |
Base path for Jinja template |
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",
"weasyprint": "string",
"wkhtmltopdf": "string",
"pypdf": "string",
"Pillow": "string",
"pdfkit": "string",
"timestamp": "number",
"pong": "string?"
}
The status
does always contain "OK".
The weasyprint
does contain the current weasyprint version.
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 | Required | Description |
---|---|---|---|
html |
file or string |
Semi-Required | HTML file to convert. html or url or report one is required. Only either url or html, report should be used. |
url |
file or string |
Semi-Required | URL to convert. html or url or report one is required. Only either url or html, report should be used. |
report |
string |
Semi-Required | Report template name to render the html. html or url or report one is required. Only either url or html, report should be used. |
data |
dict |
Semi-Required | Variables as dictionary for rendering report template. Used along with report parameter. Only either data or data_set should be used. |
data_set |
dict[] |
Semi-Required | List of "Variables as dictionary" for rendering multiple report. Used along with report parameter. Only either data or data_set should be used. |
optimize_images |
boolean |
Optional | Whether size of embedded images should be optimized, with no quality loss. |
disposition |
string |
Optional | Set response disposition type(attachment or inline). default is inline. |
file_name |
string |
Optional | Set response disposition file_name . default is document.pdf . |
password |
string |
Optional | Password protected PDF |
template |
string |
Optional | Template name for the use of predefined templates. |
driver |
string |
Optional | wk|weasy(default) wk=wkhtnltopdf weasy=Weasyprint |
options |
json |
Optional | Only with driver=wk all supported wkhtmltopdf options are supported |
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
also the header Content-Disposition = 'inline;filename={HTML_FILE_NAME}.pdf
will be set.
Service to merge pdf and/or images
POST /api/v1.0/merge
Parameter | Type | Required | Description |
---|---|---|---|
files[] |
file or files |
Required | PDF or Image file |
pages |
string |
Required | Pages definition as string or JSON |
disposition |
string |
Optional | Set response disposition type(attachment or inline). default is inline. |
file_name |
string |
Optional | Set response disposition file_name . default is merged.pdf . |
password |
string |
Optional | Password protected PDF |
[
{
"file": "file1.pdf",
"range": "0:2"
},
{
"file": "a.jpeg"
},
{
"file": "file1.pdf",
"range": "2:3"
},
{
"file": "file2.pdf"
}
]
or string like:
file1.pdf~0:2 a.jpeg file1.pdf~2:3 file2.pdf
Range | Description | Range | Description | |
---|---|---|---|---|
: | all pages. | -1 | last page. | |
22 | just the 23rd page. | :-1 | all but the last page. | |
0:3 | the first three pages. | -2 | second-to-last page. | |
:3 | the first three pages. | -2: | last two pages. | |
5: | from the sixth page onward. | -3:-1 | third & second to last. |
Range | Description | Range | Description | |
---|---|---|---|---|
::2 | 0 2 4 ... to the end. | 3:0:-1 | 3 2 1 but not 0. | |
1:10:2 | 1 3 5 7 9 | 2::-1 | 2 1 0. | |
::-1 | all pages in reverse order. |
Raw output stream of with Content-Type
of application/pdf
also the header Content-Disposition = 'inline;filename=merged.pdf
will be set.
This library was a forked from weasyprint-rest.
It usages following tools and libraries