Get 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.
Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYYAPI Email + API Key
The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.
X-Auth-Email: user@example.comThe previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.
X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194Accepted Permissions (at least one required)
Browser Rendering WriteParametersExpand Collapse
params PDFNewParams
Body param: Set the content of the page, eg: <h1>Hello World!!</h1>. Either html or url must be set.
Query param: Cache TTL default is 5s. Set to 0 to disable.
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.
AddScriptTag param.Field[[]PDFNewParamsVariant0AddScriptTag]optionalBody param: Adds a <script> tag into the page with the desired URL or content.
Body param: Adds a <script> tag into the page with the desired URL or content.
AddStyleTag param.Field[[]PDFNewParamsVariant0AddStyleTag]optionalBody param: Adds a <link rel="stylesheet"> tag into the page with the desired URL or a <style type="text/css"> tag with the content.
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.
Body param: Only allow requests that match the provided regex patterns, eg. '/^.*.(css)'.
AllowResourceTypes param.Field[[]PDFNewParamsVariant0AllowResourceType]optionalBody param: Only allow requests that match the provided resource types, eg. 'image' or 'script'.
Body param: Only allow requests that match the provided resource types, eg. 'image' or 'script'.
Body param: Attempt to proceed when 'awaited' events fail or timeout.
Cookies param.Field[[]PDFNewParamsVariant0Cookie]optionalBody param: Check options.
Body param: Check options.
Body param: Check options.
Body param: Check options.
WaitUntil PDFNewParamsVariant0GotoOptionsWaitUntilUnionoptional
PDFNewParamsVariant0GotoOptionsWaitUntilString
PDFNewParamsVariant0GotoOptionsWaitUntilArray
Body param: Check options.
Body param: Check options.
Format PDFNewParamsVariant0PDFOptionsFormatoptionalPaper format. Takes priority over width and height if set.
Paper format. Takes priority over width and height if set.
Height PDFNewParamsVariant0PDFOptionsHeightUnionoptionalSets the height of paper. Can be a number or string with unit.
Sets the height of paper. Can be a number or string with unit.
Margin PDFNewParamsVariant0PDFOptionsMarginoptionalSet the PDF margins. Useful when setting header and footer.
Set the PDF margins. Useful when setting header and footer.
Hides default white background and allows generating pdfs with transparency.
Body param: Block undesired requests that match the provided regex patterns, eg. '/^.*.(css)'.
RejectResourceTypes param.Field[[]PDFNewParamsVariant0RejectResourceType]optionalBody param: Block undesired requests that match the provided resource types, eg. 'image' or 'script'.
Body param: Block undesired requests that match the provided resource types, eg. 'image' or 'script'.
Body param: Check options.
Body param: Check options.
Body param: Wait for the selector to appear in page. Check options.
Body param: Wait for the selector to appear in page. Check options.
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
}