Skip to content

Commit 0d3ba74

Browse files
kathaylToriLindsay
andauthored
Update pdf-endpoint.mdx (#25761)
* Update pdf-endpoint.mdx add additional pdf examples https://jira.cfdata.org/browse/BRAPI-234 * Update pdf-endpoint.mdx rearrange and change titles * Update src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx Co-authored-by: ToriLindsay <[email protected]> --------- Co-authored-by: ToriLindsay <[email protected]>
1 parent dfb78df commit 0d3ba74

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,62 @@ curl -X POST https://api.cloudflare.com/client/v4/accounts/<acccountID>/browser-
142142
--output "cloudflare.pdf"
143143
```
144144

145+
### Customize page headers and footers
146+
147+
You can customize page headers and footers with HTML templates using the `headerTemplate` and `footerTemplate` options. Enable `displayHeaderFooter` to include them in your output. This example generates an A5 PDF with a branded header, a footer message, and page numbering.
148+
149+
```bash
150+
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-rendering/pdf' \
151+
-H 'Authorization: Bearer <apiToken>' \
152+
-H 'Content-Type: application/json' \
153+
-d '{
154+
"url": "https://example.com",
155+
"pdfOptions": {
156+
"format": "a5",
157+
"headerTemplate": "<div style=\"font-size: 10px; text-align: center; width: 100%; padding: 5px;\"><span>brand name</span></div>",
158+
"displayHeaderFooter": true,
159+
"footerTemplate": "<div style=\"color: lightgray; border-top: solid lightgray 1px; font-size: 10px; padding-top: 5px; text-align: center; width: 100%;\"><span>This is a test message</span> - <span class=\"pageNumber\"></span></div>",
160+
"margin": {
161+
"top": "70px",
162+
"bottom": "70px"
163+
}
164+
}
165+
}' \
166+
--output "header-footer.pdf"
167+
```
168+
169+
### Include dynamic placeholders from page metadata
170+
171+
You can include dynamic placeholders such as `title`, `date`, `pageNumber`, and `totalPages` in the header or footer to display metadata on each page. This example produces an A4 PDF with a company-branded header, current date and title, and page numbering in the footer.
172+
173+
```bash
174+
curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-rendering/pdf' \
175+
-H 'Authorization: Bearer <apiToken>' \
176+
-H 'Content-Type: application/json' \
177+
-d '{
178+
"url": "https://news.ycombinator.com",
179+
"pdfOptions": {
180+
"format": "a4",
181+
"landscape": false,
182+
"printBackground": true,
183+
"preferCSSPageSize": true,
184+
"displayHeaderFooter": true,
185+
"scale": 1.0,
186+
"headerTemplate": "<div style=\"width: 100%; font-size: 10px; padding: 10px; text-align: center;\"><div style=\"border-bottom: 1px solid #ddd;\"><span style=\"color: #666;\">Company Name</span> | <span class=\"date\"></span> | <span class=\"title\"></span></div></div>",
187+
"footerTemplate": "<div style=\"width: 100%; font-size: 10px; padding: 10px; text-align: center;\"><div style=\"border-top: 1px solid #ddd;\">Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></div></div>",
188+
"margin": {
189+
"top": "100px",
190+
"bottom": "80px",
191+
"right": "30px",
192+
"left": "30px"
193+
},
194+
"timeout": 30000
195+
}
196+
145197
<Render
146198
file="setting-custom-user-agent"
147199
product="browser-rendering"
148200
/>
201+
}' \
202+
--output "paginated.pdf"
203+
```

0 commit comments

Comments
 (0)