1
1
# html2pdf
2
+
2
3
An HTML to PDF converter provided by RESTful API and command-line tool. Powered by ` puppeteer ` .
3
4
4
5
## RESTful API
6
+
5
7
The best reason to use this method is that we can use it on any programming languages and software that support HTTP requests.
6
8
7
9
### Start server with Docker (recommended)
10
+
8
11
``` bash
9
12
docker run -p 3000:3000 iamdual/html2pdf
10
13
```
11
14
12
15
### Start server with source
16
+
13
17
``` bash
14
18
git clone https://github.com/iamdual/html2pdf && cd html2pdf
15
19
npm install
16
20
npm start
17
21
```
18
22
19
- ### Example usage (JSON POST)
23
+ ### API request with POST JSON
24
+
20
25
``` bash
21
26
curl -X POST ' http://localhost:3000/generate' \
22
27
--header ' Content-Type: application/json' \
@@ -27,13 +32,16 @@ curl -X POST 'http://localhost:3000/generate' \
27
32
}' > google.pdf
28
33
```
29
34
30
- ### Example usage (Query parameters)
35
+ ### API request with query parameters
36
+
31
37
``` bash
32
38
curl ' http://localhost:3000/generate?source=https://google.com&timeout=10' > google.pdf
33
39
```
34
40
35
41
## Command-line tool
42
+
36
43
It also support for command-line interface, so you can convert easily to a PDF.
44
+
37
45
``` bash
38
46
npm install -g https://github.com/iamdual/html2pdf
39
47
html2pdf ' <!DOCTYPE html><strong>Hello world!</strong>' -o output.pdf
@@ -42,8 +50,9 @@ html2pdf ./example.html --format A4 --pageRanges 1 -o example.pdf
42
50
```
43
51
44
52
## Parameters
53
+
45
54
| Name | Type | Description |
46
- | ------------ | --------- | ------------------------------------------------------------------------------------------------------------------------------------- |
55
+ | ---------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------- |
47
56
| source | string | Set PDF document source. It must be specified. The source can be a URL or an HTML code. |
48
57
| timeout | integer | Set connection timeout. Default is ` 10 ` . |
49
58
| javascript | boolean | Enable JavaScripts. To enable, the value should be true. Disabled by default. |
@@ -57,4 +66,5 @@ html2pdf ./example.html --format A4 --pageRanges 1 -o example.pdf
57
66
| margin | string | Set margin(s) for the PDF document. It can be all four margin or specified by the values separated with space. Default is ` 0 ` . |
58
67
59
68
## Author
69
+
60
70
Ekin Karadeniz (iamdual@icloud.com )
0 commit comments