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.

HTML param.Field[string]

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

minLength1
CacheTTL param.Field[float64]optional

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

maximum86400
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[[]PDFNewParamsVariant0AddScriptTag]optional

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

ID stringoptional
Content stringoptional
Type stringoptional
URL stringoptional
AddStyleTag param.Field[[]PDFNewParamsVariant0AddStyleTag]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
AllowRequestPattern param.Field[[]string]optional

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

AllowResourceTypes param.Field[[]PDFNewParamsVariant0AllowResourceType]optional

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

const PDFNewParamsVariant0AllowResourceTypeDocument PDFNewParamsVariant0AllowResourceType = "document"
const PDFNewParamsVariant0AllowResourceTypeStylesheet PDFNewParamsVariant0AllowResourceType = "stylesheet"
const PDFNewParamsVariant0AllowResourceTypeImage PDFNewParamsVariant0AllowResourceType = "image"
const PDFNewParamsVariant0AllowResourceTypeMedia PDFNewParamsVariant0AllowResourceType = "media"
const PDFNewParamsVariant0AllowResourceTypeFont PDFNewParamsVariant0AllowResourceType = "font"
const PDFNewParamsVariant0AllowResourceTypeScript PDFNewParamsVariant0AllowResourceType = "script"
const PDFNewParamsVariant0AllowResourceTypeTexttrack PDFNewParamsVariant0AllowResourceType = "texttrack"
const PDFNewParamsVariant0AllowResourceTypeXHR PDFNewParamsVariant0AllowResourceType = "xhr"
const PDFNewParamsVariant0AllowResourceTypeFetch PDFNewParamsVariant0AllowResourceType = "fetch"
const PDFNewParamsVariant0AllowResourceTypePrefetch PDFNewParamsVariant0AllowResourceType = "prefetch"
const PDFNewParamsVariant0AllowResourceTypeEventsource PDFNewParamsVariant0AllowResourceType = "eventsource"
const PDFNewParamsVariant0AllowResourceTypeWebsocket PDFNewParamsVariant0AllowResourceType = "websocket"
const PDFNewParamsVariant0AllowResourceTypeManifest PDFNewParamsVariant0AllowResourceType = "manifest"
const PDFNewParamsVariant0AllowResourceTypeSignedexchange PDFNewParamsVariant0AllowResourceType = "signedexchange"
const PDFNewParamsVariant0AllowResourceTypePing PDFNewParamsVariant0AllowResourceType = "ping"
const PDFNewParamsVariant0AllowResourceTypeCspviolationreport PDFNewParamsVariant0AllowResourceType = "cspviolationreport"
const PDFNewParamsVariant0AllowResourceTypePreflight PDFNewParamsVariant0AllowResourceType = "preflight"
const PDFNewParamsVariant0AllowResourceTypeOther PDFNewParamsVariant0AllowResourceType = "other"
Authenticate param.Field[PDFNewParamsVariant0Authenticate]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[[]PDFNewParamsVariant0Cookie]optional

Body param: Check options.

Name string

Cookie name.

Value string
Domain stringoptional
Expires float64optional
HTTPOnly booloptional
PartitionKey stringoptional
Path stringoptional
Priority PDFNewParamsVariant0CookiesPriorityoptional
One of the following:
const PDFNewParamsVariant0CookiesPriorityLow PDFNewParamsVariant0CookiesPriority = "Low"
const PDFNewParamsVariant0CookiesPriorityMedium PDFNewParamsVariant0CookiesPriority = "Medium"
const PDFNewParamsVariant0CookiesPriorityHigh PDFNewParamsVariant0CookiesPriority = "High"
SameParty booloptional
SameSite PDFNewParamsVariant0CookiesSameSiteoptional
One of the following:
const PDFNewParamsVariant0CookiesSameSiteStrict PDFNewParamsVariant0CookiesSameSite = "Strict"
const PDFNewParamsVariant0CookiesSameSiteLax PDFNewParamsVariant0CookiesSameSite = "Lax"
const PDFNewParamsVariant0CookiesSameSiteNone PDFNewParamsVariant0CookiesSameSite = "None"
Secure booloptional
SourcePort float64optional
SourceScheme PDFNewParamsVariant0CookiesSourceSchemeoptional
One of the following:
const PDFNewParamsVariant0CookiesSourceSchemeUnset PDFNewParamsVariant0CookiesSourceScheme = "Unset"
const PDFNewParamsVariant0CookiesSourceSchemeNonSecure PDFNewParamsVariant0CookiesSourceScheme = "NonSecure"
const PDFNewParamsVariant0CookiesSourceSchemeSecure PDFNewParamsVariant0CookiesSourceScheme = "Secure"
URL stringoptional
EmulateMediaType param.Field[string]optional

Body param

GotoOptions param.Field[PDFNewParamsVariant0GotoOptions]optional

Body param: Check options.

Referer stringoptional
ReferrerPolicy stringoptional
Timeout float64optional
maximum60000
WaitUntil PDFNewParamsVariant0GotoOptionsWaitUntilUnionoptional
One of the following:
PDFNewParamsVariant0GotoOptionsWaitUntilString
One of the following:
const PDFNewParamsVariant0GotoOptionsWaitUntilStringLoad PDFNewParamsVariant0GotoOptionsWaitUntilString = "load"
const PDFNewParamsVariant0GotoOptionsWaitUntilStringDomcontentloaded PDFNewParamsVariant0GotoOptionsWaitUntilString = "domcontentloaded"
const PDFNewParamsVariant0GotoOptionsWaitUntilStringNetworkidle0 PDFNewParamsVariant0GotoOptionsWaitUntilString = "networkidle0"
const PDFNewParamsVariant0GotoOptionsWaitUntilStringNetworkidle2 PDFNewParamsVariant0GotoOptionsWaitUntilString = "networkidle2"
PDFNewParamsVariant0GotoOptionsWaitUntilArray
One of the following:
const PDFNewParamsVariant0GotoOptionsWaitUntilArrayLoad PDFNewParamsVariant0GotoOptionsWaitUntilArray = "load"
const PDFNewParamsVariant0GotoOptionsWaitUntilArrayDomcontentloaded PDFNewParamsVariant0GotoOptionsWaitUntilArray = "domcontentloaded"
const PDFNewParamsVariant0GotoOptionsWaitUntilArrayNetworkidle0 PDFNewParamsVariant0GotoOptionsWaitUntilArray = "networkidle0"
const PDFNewParamsVariant0GotoOptionsWaitUntilArrayNetworkidle2 PDFNewParamsVariant0GotoOptionsWaitUntilArray = "networkidle2"
PDFOptions param.Field[PDFNewParamsVariant0PDFOptions]optional

Body param: Check options.

DisplayHeaderFooter booloptional

Whether to show the header and footer.

FooterTemplate stringoptional

HTML template for the print footer.

Format PDFNewParamsVariant0PDFOptionsFormatoptional

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

One of the following:
const PDFNewParamsVariant0PDFOptionsFormatLetter PDFNewParamsVariant0PDFOptionsFormat = "letter"
const PDFNewParamsVariant0PDFOptionsFormatLegal PDFNewParamsVariant0PDFOptionsFormat = "legal"
const PDFNewParamsVariant0PDFOptionsFormatTabloid PDFNewParamsVariant0PDFOptionsFormat = "tabloid"
const PDFNewParamsVariant0PDFOptionsFormatLedger PDFNewParamsVariant0PDFOptionsFormat = "ledger"
const PDFNewParamsVariant0PDFOptionsFormatA0 PDFNewParamsVariant0PDFOptionsFormat = "a0"
const PDFNewParamsVariant0PDFOptionsFormatA1 PDFNewParamsVariant0PDFOptionsFormat = "a1"
const PDFNewParamsVariant0PDFOptionsFormatA2 PDFNewParamsVariant0PDFOptionsFormat = "a2"
const PDFNewParamsVariant0PDFOptionsFormatA3 PDFNewParamsVariant0PDFOptionsFormat = "a3"
const PDFNewParamsVariant0PDFOptionsFormatA4 PDFNewParamsVariant0PDFOptionsFormat = "a4"
const PDFNewParamsVariant0PDFOptionsFormatA5 PDFNewParamsVariant0PDFOptionsFormat = "a5"
const PDFNewParamsVariant0PDFOptionsFormatA6 PDFNewParamsVariant0PDFOptionsFormat = "a6"
HeaderTemplate stringoptional

HTML template for the print header.

Height PDFNewParamsVariant0PDFOptionsHeightUnionoptional

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 PDFNewParamsVariant0PDFOptionsMarginoptional

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

Bottom PDFNewParamsVariant0PDFOptionsMarginBottomUnionoptional
One of the following:
UnionString
UnionFloat
Left PDFNewParamsVariant0PDFOptionsMarginLeftUnionoptional
One of the following:
UnionString
UnionFloat
Right PDFNewParamsVariant0PDFOptionsMarginRightUnionoptional
One of the following:
UnionString
UnionFloat
Top PDFNewParamsVariant0PDFOptionsMarginTopUnionoptional
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 PDFNewParamsVariant0PDFOptionsWidthUnionoptional

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[[]PDFNewParamsVariant0RejectResourceType]optional

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

const PDFNewParamsVariant0RejectResourceTypeDocument PDFNewParamsVariant0RejectResourceType = "document"
const PDFNewParamsVariant0RejectResourceTypeStylesheet PDFNewParamsVariant0RejectResourceType = "stylesheet"
const PDFNewParamsVariant0RejectResourceTypeImage PDFNewParamsVariant0RejectResourceType = "image"
const PDFNewParamsVariant0RejectResourceTypeMedia PDFNewParamsVariant0RejectResourceType = "media"
const PDFNewParamsVariant0RejectResourceTypeFont PDFNewParamsVariant0RejectResourceType = "font"
const PDFNewParamsVariant0RejectResourceTypeScript PDFNewParamsVariant0RejectResourceType = "script"
const PDFNewParamsVariant0RejectResourceTypeTexttrack PDFNewParamsVariant0RejectResourceType = "texttrack"
const PDFNewParamsVariant0RejectResourceTypeXHR PDFNewParamsVariant0RejectResourceType = "xhr"
const PDFNewParamsVariant0RejectResourceTypeFetch PDFNewParamsVariant0RejectResourceType = "fetch"
const PDFNewParamsVariant0RejectResourceTypePrefetch PDFNewParamsVariant0RejectResourceType = "prefetch"
const PDFNewParamsVariant0RejectResourceTypeEventsource PDFNewParamsVariant0RejectResourceType = "eventsource"
const PDFNewParamsVariant0RejectResourceTypeWebsocket PDFNewParamsVariant0RejectResourceType = "websocket"
const PDFNewParamsVariant0RejectResourceTypeManifest PDFNewParamsVariant0RejectResourceType = "manifest"
const PDFNewParamsVariant0RejectResourceTypeSignedexchange PDFNewParamsVariant0RejectResourceType = "signedexchange"
const PDFNewParamsVariant0RejectResourceTypePing PDFNewParamsVariant0RejectResourceType = "ping"
const PDFNewParamsVariant0RejectResourceTypeCspviolationreport PDFNewParamsVariant0RejectResourceType = "cspviolationreport"
const PDFNewParamsVariant0RejectResourceTypePreflight PDFNewParamsVariant0RejectResourceType = "preflight"
const PDFNewParamsVariant0RejectResourceTypeOther PDFNewParamsVariant0RejectResourceType = "other"
SetExtraHTTPHeaders param.Field[map[string, string]]optional

Body param

SetJavaScriptEnabled param.Field[bool]optional

Body param

UserAgent param.Field[string]optional

Body param

Viewport param.Field[PDFNewParamsVariant0Viewport]optional

Body param: Check options.

Height float64
Width float64
DeviceScaleFactor float64optional
HasTouch booloptional
IsLandscape booloptional
IsMobile booloptional
WaitForSelector param.Field[PDFNewParamsVariant0WaitForSelector]optional

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

Selector string
Hidden PDFNewParamsVariant0WaitForSelectorHiddenoptional
Timeout float64optional
maximum120000
Visible PDFNewParamsVariant0WaitForSelectorVisibleoptional
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"),
    Body: browser_rendering.PDFNewParamsBodyObject{
      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
}