-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Update pdf-endpoint.mdx #23175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Update pdf-endpoint.mdx #23175
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b5c1ff6
Update pdf-endpoint.mdx
kathayl 25076ea
Update pdf-endpoint.mdx
kathayl 560c76b
Update src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx
kathayl 667a6c3
Update src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx
kathayl c679e5d
Update src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx
kathayl 9c4dedd
Update src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx
kathayl 9a76a00
Update src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx
kathayl fc2d5e5
Update src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx
kathayl ee14aaa
Update src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx
kathayl a25a2eb
Update src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx
kathayl f047470
Update pdf-endpoint.mdx
kathayl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -7,10 +7,28 @@ sidebar: | |||
|
|
||||
| import { Tabs, TabItem } from "~/components"; | ||||
|
|
||||
| The `/pdf` endpoint instructs the browser to render the webpage as a PDF document. | ||||
| The `/pdf` endpoint instructs the browser to generate a PDF of a webpage or custom HTML using Cloudflare's headless browser rendering service. | ||||
|
|
||||
| ## Endpoint | ||||
|
|
||||
| ```txt | ||||
| https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-rendering/pdf | ||||
| ``` | ||||
|
|
||||
| ## Required Fields | ||||
| You must provide either `url` or `html`: | ||||
| - `url` (string) | ||||
| - `html` (string) | ||||
|
|
||||
kathayl marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
| ## Common Use Cases | ||||
kathayl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
|
|
||||
| - Capture a PDF of a webpage | ||||
| - Generate PDFs, such as invoices, licenses, reports, and certificates, directly from HTML | ||||
|
|
||||
| ## Basic usage | ||||
|
|
||||
| ### Convert a URL to PDF | ||||
|
|
||||
| <Tabs syncKey="workersExamples"> <TabItem label="curl"> | ||||
|
|
||||
| Navigate to `https://example.com/` and inject custom CSS and an external stylesheet. Then return the rendered page as a PDF. | ||||
|
|
@@ -51,11 +69,33 @@ console.log(content); | |||
|
|
||||
| </TabItem> </Tabs> | ||||
|
|
||||
| ### Convert Custom HTML to PDF | ||||
kathayl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
|
|
||||
| If you have raw HTML you'd like to generate a PDF from, use the `html` option. You can still apply custom styles using the `addStyleTag` parameter. | ||||
kathayl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
|
|
||||
| ```bash | ||||
| curl -X POST https://api.cloudflare.com/client/v4/accounts/<acccountID>/browser-rendering/pdf \ | ||||
| -H 'Authorization: Bearer <apiToken>' \ | ||||
| -H 'Content-Type: application/json' \ | ||||
| -d '{ | ||||
| "html": "<html><body>Advanced Snapshot</body></html>", | ||||
| "addStyleTag": [ | ||||
| { "content": "body { font-family: Arial; }" }, | ||||
| { "url": "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" } | ||||
| ] | ||||
| }' \ | ||||
| --output "invoice.pdf" | ||||
| ``` | ||||
|
|
||||
| ## Advanced usage | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
|
|
||||
| Navigate to `https://example.com`, first setting an additional HTTP request header and configuring the page size (`viewport`). Then, wait until there are no more than 2 network connections for at least 500 ms, or until the maximum timeout of 4500 ms is reached, before considering the page loaded and returning the rendered PDF document. | ||||
| Many more options exist, such as setting HTTP credentials using `authenticate`, setting `cookies`, and customizing load behavior using `gotoOptions`. **Check the full endpoint [reference](/api/resources/browser_rendering/subresources/pdf/methods/create/) for all available parameters.** | ||||
kathayl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
|
|
||||
| ### Advanced Page Load with Custom Headers and Viewport | ||||
kathayl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
|
|
||||
| The `goToOptions` parameter exposes most of [Puppeteer'd API](https://pptr.dev/api/puppeteer.gotooptions). | ||||
| Navigate to `https://example.com`, setting additional HTTP headers and configuring the page size (viewport). The PDF generation will wait until there are no more than 2 network connections for at least 500 ms, or until the maximum timeout of 4500 ms is reached, before rendering. | ||||
kathayl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
|
|
||||
| The `goToOptions` parameter exposes most of [Puppeteer's API](https://pptr.dev/api/puppeteer.gotooptions). | ||||
|
|
||||
| ```bash | ||||
| curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-rendering/pdf' \ | ||||
|
|
@@ -78,9 +118,9 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser- | |||
| --output "advanced-output.pdf" | ||||
| ``` | ||||
|
|
||||
| ## Blocking images and styles when generating a PDF | ||||
| ## Blocking Images and Styles when Generating a PDF | ||||
kathayl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
|
|
||||
| The options `rejectResourceTypes` and `rejectRequestPattern` can be used to block requests. The opposite can also be done, _only_ allow certain requests using `allowResourceTypes` and `allowRequestPattern`. | ||||
| The options `rejectResourceTypes` and `rejectRequestPattern` can be used to block requests during rendering. The opposite can also be done, _only_ allow certain requests using `allowResourceTypes` and `allowRequestPattern`. | ||||
|
|
||||
| ```bash | ||||
| curl -X POST https://api.cloudflare.com/client/v4/accounts/<acccountID>/browser-rendering/pdf \ | ||||
|
|
@@ -93,23 +133,3 @@ curl -X POST https://api.cloudflare.com/client/v4/accounts/<acccountID>/browser- | |||
| }' \ | ||||
| --output "cloudflare.pdf" | ||||
| ``` | ||||
|
|
||||
| ## Generate PDF from custom HTML | ||||
kathayl marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
|
|
||||
| If you have HTML you'd like to generate a PDF from, the `html` option can be used. The option `addStyleTag` can be used to add custom styles. | ||||
|
|
||||
| ```bash | ||||
| curl -X POST https://api.cloudflare.com/client/v4/accounts/<acccountID>/browser-rendering/pdf \ | ||||
| -H 'Authorization: Bearer <apiToken>' \ | ||||
| -H 'Content-Type: application/json' \ | ||||
| -d '{ | ||||
| "html": "<html><body>Advanced Snapshot</body></html>", | ||||
| "addStyleTag": [ | ||||
| { "content": "body { font-family: Arial; }" }, | ||||
| { "url": "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" } | ||||
| ] | ||||
| }' \ | ||||
| --output "invoice.pdf" | ||||
| ``` | ||||
|
|
||||
| Many more options exist, like setting HTTP credentials using `authenticate`, setting `cookies`, and using `gotoOptions` to control page load behaviour - check the endpoint [reference](/api/resources/browser_rendering/subresources/pdf/methods/create/) for all available parameters. | ||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.