Skip to content
Start here

Get PDF.

client.BrowserRendering.PDF.New(ctx, params) (*Response, error)
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
params PDFNewParams
AccountID param.Field[string]

Path param: Account ID.

CacheTTL param.Field[float64]Optional

Query param: Cache TTL default is 5s. Set to 0 to disable.

maximum86400
minimum0
ActionTimeout param.Field[float64]Optional

Body param: 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
AddScriptTag param.Field[[]PDFNewParamsAddScriptTag]Optional

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

ID stringOptional
Content stringOptional
Type stringOptional
URL stringOptional
formaturi
AddStyleTag param.Field[[]PDFNewParamsAddStyleTag]Optional

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

Content stringOptional
URL stringOptional
formaturi
AllowRequestPattern param.Field[[]string]Optional

Body param: Only allow requests that match the provided regex patterns, eg. ’/^.*.(css)’.

AllowResourceTypes param.Field[[]PDFNewParamsAllowResourceType]Optional

Body param: Only allow requests that match the provided resource types, eg. ‘image’ or ‘script’.

const PDFNewParamsAllowResourceTypeDocument PDFNewParamsAllowResourceType = "document"
const PDFNewParamsAllowResourceTypeStylesheet PDFNewParamsAllowResourceType = "stylesheet"
const PDFNewParamsAllowResourceTypeImage PDFNewParamsAllowResourceType = "image"
const PDFNewParamsAllowResourceTypeMedia PDFNewParamsAllowResourceType = "media"
const PDFNewParamsAllowResourceTypeFont PDFNewParamsAllowResourceType = "font"
const PDFNewParamsAllowResourceTypeScript PDFNewParamsAllowResourceType = "script"
const PDFNewParamsAllowResourceTypeTexttrack PDFNewParamsAllowResourceType = "texttrack"
const PDFNewParamsAllowResourceTypeXHR PDFNewParamsAllowResourceType = "xhr"
const PDFNewParamsAllowResourceTypeFetch PDFNewParamsAllowResourceType = "fetch"
const PDFNewParamsAllowResourceTypePrefetch PDFNewParamsAllowResourceType = "prefetch"
const PDFNewParamsAllowResourceTypeEventsource PDFNewParamsAllowResourceType = "eventsource"
const PDFNewParamsAllowResourceTypeWebsocket PDFNewParamsAllowResourceType = "websocket"
const PDFNewParamsAllowResourceTypeManifest PDFNewParamsAllowResourceType = "manifest"
const PDFNewParamsAllowResourceTypeSignedexchange PDFNewParamsAllowResourceType = "signedexchange"
const PDFNewParamsAllowResourceTypePing PDFNewParamsAllowResourceType = "ping"
const PDFNewParamsAllowResourceTypeCspviolationreport PDFNewParamsAllowResourceType = "cspviolationreport"
const PDFNewParamsAllowResourceTypePreflight PDFNewParamsAllowResourceType = "preflight"
const PDFNewParamsAllowResourceTypeOther PDFNewParamsAllowResourceType = "other"
Authenticate param.Field[PDFNewParamsAuthenticate]Optional

Body param: Provide credentials for HTTP authentication.

Password string
minLength1
Username string
minLength1
BestAttempt param.Field[bool]Optional

Body param: Attempt to proceed when ‘awaited’ events fail or timeout.

Cookies param.Field[[]PDFNewParamsCookie]Optional

Body param: Check options.

Name string

Cookie name.

Value string
Domain stringOptional
Expires float64Optional
HTTPOnly boolOptional
PartitionKey stringOptional
Path stringOptional
Priority PDFNewParamsCookiesPriorityOptional
One of the following:
const PDFNewParamsCookiesPriorityLow PDFNewParamsCookiesPriority = "Low"
const PDFNewParamsCookiesPriorityMedium PDFNewParamsCookiesPriority = "Medium"
const PDFNewParamsCookiesPriorityHigh PDFNewParamsCookiesPriority = "High"
SameParty boolOptional
SameSite PDFNewParamsCookiesSameSiteOptional
One of the following:
const PDFNewParamsCookiesSameSiteStrict PDFNewParamsCookiesSameSite = "Strict"
const PDFNewParamsCookiesSameSiteLax PDFNewParamsCookiesSameSite = "Lax"
const PDFNewParamsCookiesSameSiteNone PDFNewParamsCookiesSameSite = "None"
Secure boolOptional
SourcePort float64Optional
SourceScheme PDFNewParamsCookiesSourceSchemeOptional
One of the following:
const PDFNewParamsCookiesSourceSchemeUnset PDFNewParamsCookiesSourceScheme = "Unset"
const PDFNewParamsCookiesSourceSchemeNonSecure PDFNewParamsCookiesSourceScheme = "NonSecure"
const PDFNewParamsCookiesSourceSchemeSecure PDFNewParamsCookiesSourceScheme = "Secure"
URL stringOptional
EmulateMediaType param.Field[string]Optional

Body param

GotoOptions param.Field[PDFNewParamsGotoOptions]Optional

Body param: Check options.

Referer stringOptional
ReferrerPolicy stringOptional
Timeout float64Optional
maximum60000
WaitUntil PDFNewParamsGotoOptionsWaitUntilUnionOptional
One of the following:
type PDFNewParamsGotoOptionsWaitUntilString string
One of the following:
const PDFNewParamsGotoOptionsWaitUntilStringLoad PDFNewParamsGotoOptionsWaitUntilString = "load"
const PDFNewParamsGotoOptionsWaitUntilStringDomcontentloaded PDFNewParamsGotoOptionsWaitUntilString = "domcontentloaded"
const PDFNewParamsGotoOptionsWaitUntilStringNetworkidle0 PDFNewParamsGotoOptionsWaitUntilString = "networkidle0"
const PDFNewParamsGotoOptionsWaitUntilStringNetworkidle2 PDFNewParamsGotoOptionsWaitUntilString = "networkidle2"
type PDFNewParamsGotoOptionsWaitUntilArray []PDFNewParamsGotoOptionsWaitUntilArray
One of the following:
const PDFNewParamsGotoOptionsWaitUntilArrayItemLoad PDFNewParamsGotoOptionsWaitUntilArrayItem = "load"
const PDFNewParamsGotoOptionsWaitUntilArrayItemDomcontentloaded PDFNewParamsGotoOptionsWaitUntilArrayItem = "domcontentloaded"
const PDFNewParamsGotoOptionsWaitUntilArrayItemNetworkidle0 PDFNewParamsGotoOptionsWaitUntilArrayItem = "networkidle0"
const PDFNewParamsGotoOptionsWaitUntilArrayItemNetworkidle2 PDFNewParamsGotoOptionsWaitUntilArrayItem = "networkidle2"
HTML param.Field[string]Optional

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

minLength1
PDFOptions param.Field[PDFNewParamsPDFOptions]Optional

Body param: Check options.

DisplayHeaderFooter boolOptional

Whether to show the header and footer.

FooterTemplate stringOptional

HTML template for the print footer.

Format PDFNewParamsPDFOptionsFormatOptional

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

One of the following:
const PDFNewParamsPDFOptionsFormatLetter PDFNewParamsPDFOptionsFormat = "letter"
const PDFNewParamsPDFOptionsFormatLegal PDFNewParamsPDFOptionsFormat = "legal"
const PDFNewParamsPDFOptionsFormatTabloid PDFNewParamsPDFOptionsFormat = "tabloid"
const PDFNewParamsPDFOptionsFormatLedger PDFNewParamsPDFOptionsFormat = "ledger"
const PDFNewParamsPDFOptionsFormatA0 PDFNewParamsPDFOptionsFormat = "a0"
const PDFNewParamsPDFOptionsFormatA1 PDFNewParamsPDFOptionsFormat = "a1"
const PDFNewParamsPDFOptionsFormatA2 PDFNewParamsPDFOptionsFormat = "a2"
const PDFNewParamsPDFOptionsFormatA3 PDFNewParamsPDFOptionsFormat = "a3"
const PDFNewParamsPDFOptionsFormatA4 PDFNewParamsPDFOptionsFormat = "a4"
const PDFNewParamsPDFOptionsFormatA5 PDFNewParamsPDFOptionsFormat = "a5"
const PDFNewParamsPDFOptionsFormatA6 PDFNewParamsPDFOptionsFormat = "a6"
HeaderTemplate stringOptional

HTML template for the print header.

Height PDFNewParamsPDFOptionsHeightUnionOptional

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

One of the following:
UnionString
UnionFloat
Landscape boolOptional

Whether to print in landscape orientation.

Margin PDFNewParamsPDFOptionsMarginOptional

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

Bottom PDFNewParamsPDFOptionsMarginBottomUnionOptional
One of the following:
UnionString
UnionFloat
Left PDFNewParamsPDFOptionsMarginLeftUnionOptional
One of the following:
UnionString
UnionFloat
Right PDFNewParamsPDFOptionsMarginRightUnionOptional
One of the following:
UnionString
UnionFloat
Top PDFNewParamsPDFOptionsMarginTopUnionOptional
One of the following:
UnionString
UnionFloat
OmitBackground boolOptional

Hides default white background and allows generating pdfs with transparency.

Outline boolOptional

Generate document outline.

PageRanges stringOptional

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

PreferCSSPageSize boolOptional

Give CSS @page size priority over other size declarations.

PrintBackground boolOptional

Set to true to print background graphics.

Scale float64Optional

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

maximum2
minimum0.1
Tagged boolOptional

Generate tagged (accessible) PDF.

Timeout float64Optional

Timeout in milliseconds.

Width PDFNewParamsPDFOptionsWidthUnionOptional

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

One of the following:
UnionString
UnionFloat
RejectRequestPattern param.Field[[]string]Optional

Body param: Block undesired requests that match the provided regex patterns, eg. ’/^.*.(css)’.

RejectResourceTypes param.Field[[]PDFNewParamsRejectResourceType]Optional

Body param: Block undesired requests that match the provided resource types, eg. ‘image’ or ‘script’.

const PDFNewParamsRejectResourceTypeDocument PDFNewParamsRejectResourceType = "document"
const PDFNewParamsRejectResourceTypeStylesheet PDFNewParamsRejectResourceType = "stylesheet"
const PDFNewParamsRejectResourceTypeImage PDFNewParamsRejectResourceType = "image"
const PDFNewParamsRejectResourceTypeMedia PDFNewParamsRejectResourceType = "media"
const PDFNewParamsRejectResourceTypeFont PDFNewParamsRejectResourceType = "font"
const PDFNewParamsRejectResourceTypeScript PDFNewParamsRejectResourceType = "script"
const PDFNewParamsRejectResourceTypeTexttrack PDFNewParamsRejectResourceType = "texttrack"
const PDFNewParamsRejectResourceTypeXHR PDFNewParamsRejectResourceType = "xhr"
const PDFNewParamsRejectResourceTypeFetch PDFNewParamsRejectResourceType = "fetch"
const PDFNewParamsRejectResourceTypePrefetch PDFNewParamsRejectResourceType = "prefetch"
const PDFNewParamsRejectResourceTypeEventsource PDFNewParamsRejectResourceType = "eventsource"
const PDFNewParamsRejectResourceTypeWebsocket PDFNewParamsRejectResourceType = "websocket"
const PDFNewParamsRejectResourceTypeManifest PDFNewParamsRejectResourceType = "manifest"
const PDFNewParamsRejectResourceTypeSignedexchange PDFNewParamsRejectResourceType = "signedexchange"
const PDFNewParamsRejectResourceTypePing PDFNewParamsRejectResourceType = "ping"
const PDFNewParamsRejectResourceTypeCspviolationreport PDFNewParamsRejectResourceType = "cspviolationreport"
const PDFNewParamsRejectResourceTypePreflight PDFNewParamsRejectResourceType = "preflight"
const PDFNewParamsRejectResourceTypeOther PDFNewParamsRejectResourceType = "other"
SetExtraHTTPHeaders param.Field[map[string, string]]Optional

Body param

SetJavaScriptEnabled param.Field[bool]Optional

Body param

URL param.Field[string]Optional

Body param: URL to navigate to, eg. https://example.com.

formaturi
UserAgent param.Field[string]Optional

Body param

Viewport param.Field[PDFNewParamsViewport]Optional

Body param: Check options.

Height float64
Width float64
DeviceScaleFactor float64Optional
HasTouch boolOptional
IsLandscape boolOptional
IsMobile boolOptional
WaitForSelector param.Field[PDFNewParamsWaitForSelector]Optional

Body param: Wait for the selector to appear in page. Check options.

Selector string
Hidden PDFNewParamsWaitForSelectorHiddenOptional
Timeout float64Optional
maximum120000
Visible PDFNewParamsWaitForSelectorVisibleOptional
WaitForTimeout param.Field[float64]Optional

Body param: Waits for a specified timeout before continuing.

maximum120000
ReturnsExpand Collapse
type PDFNewResponse interface{…}

Get PDF.

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/browser_rendering"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  pdf, err := client.BrowserRendering.PDF.New(context.TODO(), browser_rendering.PDFNewParams{
    AccountID: cloudflare.F("account_id"),
    URL: cloudflare.F("https://www.example.com/"),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", pdf)
}
{
  "errors": [
    {
      "code": 2001,
      "message": "Rate limit exceeded"
    }
  ],
  "success": false
}
Returns Examples
{
  "errors": [
    {
      "code": 2001,
      "message": "Rate limit exceeded"
    }
  ],
  "success": false
}