Run in docker container:
docker run -p 3000:3000 -d --restart always cempehlivan/html-to-pdfRun in NodeJS:
cd app
..
npm install
..
node app.jsswagger documentation url: http://localhost:3000/api-docs
html to pdf endpoint: http://localhost:3000/converter/htmltopdf
| Parameter | Type | Description |
|---|---|---|
| html | HTML string | required |
| options | PDFOptions | (Optional) |
| Property | Type | Description |
|---|---|---|
| displayHeaderFooter? | boolean | (Optional) Whether to show the header and footer. |
| footerTemplate? | string | (Optional) HTML template for the print footer. Has the same constraints and support for special classes as headerTemplate. |
| format? | PaperFormat | (Optional) |
| headerTemplate? | string | (Optional) HTML template for the print header. Should be valid HTML with the following classes used to inject values into them: - - - - - |
| height? | string | number | (Optional) Sets the height of paper. You can pass in a number or a string with a unit. |
| landscape? | boolean | (Optional) Whether to print in landscape orientation. |
| margin? | PDFMargin | (Optional) Set the PDF margins. |
| omitBackground? | boolean | (Optional) Hides default white background and allows generating pdfs with transparency. |
| pageRanges? | string | (Optional) Paper ranges to print, e.g. 1-5, 8, 11-13. |
| path? | string | (Optional) The path to save the file to. |
| preferCSSPageSize? | boolean | (Optional) Give any CSS @page size declared in the page priority over what is declared in the width or height or format option. |
| printBackground? | boolean | (Optional) Set to true to print background graphics. |
| scale? | number | (Optional) Scales the rendering of the web page. Amount must be between 0.1 and 2. |
| timeout? | number | (Optional) Timeout in milliseconds |
| width? | string | number | (Optional) Sets the width of paper. You can pass in a number or a string with a unit. |
The sizes of each format are as follows: - Letter: 8.5in x 11in
-
Legal: 8.5in x 14in -
Tabloid: 11in x 17in -
Ledger: 17in x 11in -
A0: 33.1in x 46.8in -
A1: 23.4in x 33.1in -
A2: 16.54in x 23.4in -
A3: 11.7in x 16.54in -
A4: 8.27in x 11.7in -
A5: 5.83in x 8.27in -
A6: 4.13in x 5.83in
| Property | Modifiers | Type | Description |
|---|---|---|---|
| bottom? | string | number | (Optional) | |
| left? | string | number | (Optional) | |
| right? | string | number | (Optional) | |
| top? | string | number | (Optional) |
{
"html": "<h1>test</h1>",
"options": {
"format": "A4",
"printBackground": true,
"margin": {
"top": "10.5mm",
"left": "10.5mm",
"right": "10.5mm",
"bottom": "10.5mm"
}
}
}{
"status": "success",
"data": {
"pdf": "<base64pdf>"
}
}