From 2b329ff5d377b7cfa99a5becc2576112f50e8c78 Mon Sep 17 00:00:00 2001 From: Kathy <153706637+kathayl@users.noreply.github.com> Date: Fri, 10 Oct 2025 10:35:16 -0400 Subject: [PATCH 1/2] Update pdf-endpoint.mdx add additional pdf examples https://jira.cfdata.org/browse/BRAPI-234 --- .../rest-api/pdf-endpoint.mdx | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx b/src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx index 8261c23b3a3bf3..525aad5508b22d 100644 --- a/src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx +++ b/src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx @@ -142,3 +142,58 @@ curl -X POST https://api.cloudflare.com/client/v4/accounts//browser- file="setting-custom-user-agent" product="browser-rendering" /> + +### Generate a PDF with custom header and footer + +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. + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/pdf' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://example.com", + "pdfOptions": { + "format": "a5", + "headerTemplate": "
brand name
", + "displayHeaderFooter": true, + "footerTemplate": "
This is a test message -
", + "margin": { + "top": "70px", + "bottom": "70px" + } + } + }' \ + --output "header-footer.pdf" +``` + +### Generate a PDF with page numbers and metadata + +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. + +```bash +curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/pdf' \ + -H 'Authorization: Bearer ' \ + -H 'Content-Type: application/json' \ + -d '{ + "url": "https://news.ycombinator.com", + "pdfOptions": { + "format": "a4", + "landscape": false, + "printBackground": true, + "preferCSSPageSize": true, + "displayHeaderFooter": true, + "scale": 1.0, + "headerTemplate": "
Company Name | |
", + "footerTemplate": "
Page of
", + "margin": { + "top": "100px", + "bottom": "80px", + "right": "30px", + "left": "30px" + }, + "timeout": 30000 + } + }' \ + --output "paginated.pdf" +``` From 8fb17e263bf87617d34fa97f7dcdb7315bd8f8a8 Mon Sep 17 00:00:00 2001 From: Kathy <153706637+kathayl@users.noreply.github.com> Date: Fri, 10 Oct 2025 11:22:59 -0400 Subject: [PATCH 2/2] Update pdf-endpoint.mdx rearrange and change titles --- .../browser-rendering/rest-api/pdf-endpoint.mdx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx b/src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx index 525aad5508b22d..e1377b336c7b70 100644 --- a/src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx +++ b/src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx @@ -138,14 +138,9 @@ curl -X POST https://api.cloudflare.com/client/v4/accounts//browser- --output "cloudflare.pdf" ``` - - -### Generate a PDF with custom header and footer +### Customize page headers and footers -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. +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. ```bash curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser-rendering/pdf' \ @@ -167,7 +162,7 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- --output "header-footer.pdf" ``` -### Generate a PDF with page numbers and metadata +### Include dynamic placeholders from page metadata 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. @@ -194,6 +189,11 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts//browser- }, "timeout": 30000 } + + }' \ --output "paginated.pdf" ```