You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: enhance API to support direct HTML content rendering alongside URL rendering
### Changes
- Updated README.md to reflect new feature allowing HTML content to be passed directly for rendering.
- Modified PuppeteerWrapper to handle both URL and HTML content, ensuring either can be provided for rendering.
- Adjusted Swagger API documentation to indicate that either 'url' or 'html' must be supplied in requests.
- Enhanced validation logic to enforce the requirement of at least one of 'url' or 'html' in the request configuration.
### Problem Solved
This update allows users to generate PDFs and images directly from HTML content, improving flexibility for various use cases.
Copy file name to clipboardExpand all lines: README.md
+104-3Lines changed: 104 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,9 +17,10 @@ It provides a basic yet performant wrapper along with additional features to enh
17
17
18
18
## Features
19
19
20
-
✅ Generate PNG images from any URL<br>
21
-
✅ Generate PDFs from any URL<br>
20
+
✅ Generate PNG images from any URL or HTML content<br>
21
+
✅ Generate PDFs from any URL or HTML content<br>
22
22
✅ Generate Videos from any URL with smooth animation<br>
23
+
✅ **Direct HTML rendering** - Pass HTML content directly without needing a URL<br>
23
24
✅ Support for custom headers (like Authorization)<br>
24
25
✅ Support to render Lazy animations<br>
25
26
✅ Additional support for blocking: Cookies, Ads, Trackers, Banner<br>
@@ -33,16 +34,116 @@ For usage in commercial services, please refer to the `license.txt` file in this
33
34
34
35
Note: License is not enforced, but we are a small team, and any support to further develop this product would be greatly appreciated! 🙏
35
36
36
-
## How to create your API call
37
+
## API Usage
38
+
39
+
### Render from URL
37
40
38
41
Use the Playground at [html2pdfapi](https://html2pdfapi.com/playground) (a free account is required), to create the API request in your favorite language.
39
42
You can omit the `apiKey` parameter.
40
43
44
+
**Example - Generate PDF from URL:**
45
+
```bash
46
+
curl -X POST http://localhost:3000/render \
47
+
-H "Content-Type: application/json" \
48
+
-d '{
49
+
"url": "https://example.com",
50
+
"type": "pdf"
51
+
}' \
52
+
--output output.pdf
53
+
```
54
+
55
+
### Render from HTML Content
56
+
57
+
You can now pass HTML content directly to the API without needing a URL! This is perfect for:
58
+
- Generating PDFs from dynamically created HTML
59
+
- Creating images from HTML templates
60
+
- Converting HTML email templates to images
61
+
- Any scenario where you have HTML as a string
62
+
63
+
**Example - Generate PDF from HTML:**
64
+
```bash
65
+
curl -X POST http://localhost:3000/render \
66
+
-H "Content-Type: application/json" \
67
+
-d '{
68
+
"html": "<!DOCTYPE html><html><head><title>My Document</title><style>body { font-family: Arial; padding: 40px; } h1 { color: #333; }</style></head><body><h1>Hello World!</h1><p>This PDF was generated from HTML content.</p></body></html>",
- Either `url` OR `html` must be provided (not both)
113
+
- All standard options (device settings, PDF options, image options, etc.) work with both URL and HTML modes
114
+
- When using HTML content, network idle wait conditions (`networkidle0`, `networkidle2`) are automatically adjusted to prevent timeouts
115
+
41
116
The Saas solution of our service provides out-of-the-box async support so that you don't have to implement your own.
42
117
43
118
There are many libraries you can use to achieve it, it depends on the language you are using, this is a very lightweight and versatile solution if you are looking
44
119
for a simple, yet performant solution.
45
120
121
+
## API Reference
122
+
123
+
### Endpoints
124
+
125
+
| Endpoint | Method | Description |
126
+
|----------|--------|-------------|
127
+
|`/render`| POST | Render URL or HTML to PDF/Image/Video |
128
+
|`/render?config=...`| GET | Render URL using GET with JSON config parameter |
129
+
|`/health`| GET | Health check with browser pool stats |
130
+
|`/docs`| GET | Swagger API documentation |
131
+
132
+
### Request Parameters
133
+
134
+
| Parameter | Type | Required | Description |
135
+
|-----------|------|----------|-------------|
136
+
|`url`| string | Either url or html | URL to render |
137
+
|`html`| string | Either url or html | HTML content to render |
0 commit comments