Skip to content
Start here

Get PDF.

browser_rendering.pdf.create(PDFCreateParams**kwargs) -> BinaryResponseContent
POST/accounts/{account_id}/browser-rendering/pdf

Fetches rendered PDF from provided URL or HTML. Check available options like gotoOptions and waitFor* to control page load behaviour.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Browser Rendering Write
ParametersExpand Collapse
account_id: str

Account ID.

html: str

Set the content of the page, eg: <h1>Hello World!!</h1>. Either html or url must be set.

minLength1
cache_ttl: Optional[float]

Cache TTL default is 5s. Set to 0 to disable.

maximum86400
action_timeout: Optional[float]

The maximum duration allowed for the browser action to complete after the page has loaded (such as taking screenshots, extracting content, or generating PDFs). If this time limit is exceeded, the action stops and returns a timeout error.

maximum120000
add_script_tag: Optional[Iterable[Variant0AddScriptTag]]

Adds a <script> tag into the page with the desired URL or content.

id: Optional[str]
content: Optional[str]
type: Optional[str]
url: Optional[str]
add_style_tag: Optional[Iterable[Variant0AddStyleTag]]

Adds a <link rel="stylesheet"> tag into the page with the desired URL or a <style type="text/css"> tag with the content.

content: Optional[str]
url: Optional[str]
allow_request_pattern: Optional[SequenceNotStr[str]]

Only allow requests that match the provided regex patterns, eg. '/^.*.(css)'.

allow_resource_types: Optional[List[Literal["document", "stylesheet", "image", 15 more]]]

Only allow requests that match the provided resource types, eg. 'image' or 'script'.

One of the following:
"document"
"stylesheet"
"image"
"media"
"font"
"script"
"texttrack"
"xhr"
"fetch"
"prefetch"
"eventsource"
"websocket"
"manifest"
"signedexchange"
"ping"
"cspviolationreport"
"preflight"
"other"
authenticate: Optional[Variant0Authenticate]

Provide credentials for HTTP authentication.

password: str
minLength1
username: str
minLength1
best_attempt: Optional[bool]

Attempt to proceed when 'awaited' events fail or timeout.

cookies: Optional[Iterable[Variant0Cookie]]

Check options.

name: str

Cookie name.

value: str
domain: Optional[str]
expires: Optional[float]
http_only: Optional[bool]
partition_key: Optional[str]
path: Optional[str]
priority: Optional[Literal["Low", "Medium", "High"]]
One of the following:
"Low"
"Medium"
"High"
same_party: Optional[bool]
same_site: Optional[Literal["Strict", "Lax", "None"]]
One of the following:
"Strict"
"Lax"
"None"
secure: Optional[bool]
source_port: Optional[float]
source_scheme: Optional[Literal["Unset", "NonSecure", "Secure"]]
One of the following:
"Unset"
"NonSecure"
"Secure"
url: Optional[str]
emulate_media_type: Optional[str]
goto_options: Optional[Variant0GotoOptions]

Check options.

referer: Optional[str]
referrer_policy: Optional[str]
timeout: Optional[float]
maximum60000
wait_until: Optional[Union[Literal["load", "domcontentloaded", "networkidle0", "networkidle2"], List[Literal["load", "domcontentloaded", "networkidle0", "networkidle2"]]]]
One of the following:
Literal["load", "domcontentloaded", "networkidle0", "networkidle2"]
One of the following:
"load"
"domcontentloaded"
"networkidle0"
"networkidle2"
List[Literal["load", "domcontentloaded", "networkidle0", "networkidle2"]]
One of the following:
"load"
"domcontentloaded"
"networkidle0"
"networkidle2"
pdf_options: Optional[Variant0PDFOptions]

Check options.

display_header_footer: Optional[bool]

Whether to show the header and footer.

footer_template: Optional[str]

HTML template for the print footer.

format: Optional[Literal["letter", "legal", "tabloid", 8 more]]

Paper format. Takes priority over width and height if set.

One of the following:
"letter"
"legal"
"tabloid"
"ledger"
"a0"
"a1"
"a2"
"a3"
"a4"
"a5"
"a6"
header_template: Optional[str]

HTML template for the print header.

height: Optional[Union[str, float]]

Sets the height of paper. Can be a number or string with unit.

One of the following:
str
float
landscape: Optional[bool]

Whether to print in landscape orientation.

margin: Optional[Variant0PDFOptionsMargin]

Set the PDF margins. Useful when setting header and footer.

bottom: Optional[Union[str, float]]
One of the following:
str
float
left: Optional[Union[str, float]]
One of the following:
str
float
right: Optional[Union[str, float]]
One of the following:
str
float
top: Optional[Union[str, float]]
One of the following:
str
float
omit_background: Optional[bool]

Hides default white background and allows generating pdfs with transparency.

outline: Optional[bool]

Generate document outline.

page_ranges: Optional[str]

Paper ranges to print, e.g. '1-5, 8, 11-13'.

prefer_css_page_size: Optional[bool]

Give CSS @page size priority over other size declarations.

print_background: Optional[bool]

Set to true to print background graphics.

scale: Optional[float]

Scales the rendering of the web page. Amount must be between 0.1 and 2.

maximum2
minimum0.1
tagged: Optional[bool]

Generate tagged (accessible) PDF.

timeout: Optional[float]

Timeout in milliseconds.

width: Optional[Union[str, float]]

Sets the width of paper. Can be a number or string with unit.

One of the following:
str
float
reject_request_pattern: Optional[SequenceNotStr[str]]

Block undesired requests that match the provided regex patterns, eg. '/^.*.(css)'.

reject_resource_types: Optional[List[Literal["document", "stylesheet", "image", 15 more]]]

Block undesired requests that match the provided resource types, eg. 'image' or 'script'.

One of the following:
"document"
"stylesheet"
"image"
"media"
"font"
"script"
"texttrack"
"xhr"
"fetch"
"prefetch"
"eventsource"
"websocket"
"manifest"
"signedexchange"
"ping"
"cspviolationreport"
"preflight"
"other"
set_extra_http_headers: Optional[Dict[str, str]]
set_java_script_enabled: Optional[bool]
user_agent: Optional[str]
viewport: Optional[Variant0Viewport]

Check options.

height: float
width: float
device_scale_factor: Optional[float]
has_touch: Optional[bool]
is_landscape: Optional[bool]
is_mobile: Optional[bool]
wait_for_selector: Optional[Variant0WaitForSelector]

Wait for the selector to appear in page. Check options.

selector: str
hidden: Optional[Literal[true]]
timeout: Optional[float]
maximum120000
visible: Optional[Literal[true]]
wait_for_timeout: Optional[float]

Waits for a specified timeout before continuing.

maximum120000
ReturnsExpand Collapse
BinaryResponseContent

Get PDF.

import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_token=os.environ.get("CLOUDFLARE_API_TOKEN"),  # This is the default and can be omitted
)
pdf = client.browser_rendering.pdf.create(
    account_id="account_id",
    html="<h1>Hello World!</h1>",
)
print(pdf)
content = pdf.read()
print(content)
{
  "errors": [
    {
      "code": 2001,
      "message": "Rate limit exceeded"
    }
  ],
  "success": false
}
Returns Examples
{
  "errors": [
    {
      "code": 2001,
      "message": "Rate limit exceeded"
    }
  ],
  "success": false
}