PDF Function
This function will generate a PDF from any webpage. TestingBot will launch a remote browser, visit the URL you specified and take a PDF from it.
Use the URLs below to take an instant PDF from a page, without having to write any code.
Instead of relying on tools such as wkhtmltopdf, PDFShift, Athena, PDFBlade or others, you can rely on the power of Chrome's rendering engine to take a high quality PDF through a Function (which uses Puppeteer behind the scenes).
Example
curl -X POST https://cloud.testingbot.com/pdf?key=YOUR_KEY&secret=YOUR_SECRET&browserName=chrome&version=latest&platform=WIN10 \
-H 'Content-Type: application/json' \
-d '{"url":"https://testingbot.com"}' > test.pdf
This simple example will run a Puppeteer script on our service and do the following:
- Start a Headless Browser (latest version) on our cloud
- Connect with Puppeteer to the Browser and navigate to the URL you specified
- Generate a PDF from the page
-
Return the
PDF file
back to you, in a file calledtest.pdf
Specifying browser and version
See the example below to specify on which platform configuration you'd like to generate the PDF on. You can specify a browserName
, version
and platform
.
PDF Options
You can specify additional options with this function call to customize the PDF taking.
This function call can use any of the Puppeteer puppeteer.pdfoptions options.
curl -X POST https://cloud.testingbot.com/pdf?key=YOUR_KEY&secret=YOUR_SECRET&browserName=chrome&version=latest&platform=WIN10 \
-H 'Content-Type: application/json' \
-d '{"url":"https://testingbot.com", "options":{"fullPage":true}}' > test.pdf
Authenticate options
You can specify the page.authenticate credentials.
curl -X POST https://cloud.testingbot.com/pdf?key=YOUR_KEY&secret=YOUR_SECRET&browserName=chrome&version=latest&platform=WIN10" \
-H 'Content-Type: application/json' \
-d '{"url":"https://testingbot.com", "authenticate":{ "username": "user", "password": "passwd" }}' > test.pdf
Goto options
You can specify the page.goto options and add timeout
and waitUntil
settings.
curl -X POST https://cloud.testingbot.com/pdf?key=YOUR_KEY&secret=YOUR_SECRET&browserName=chrome&version=latest&platform=WIN10 \
-H 'Content-Type: application/json' \
-d '{"url":"https://testingbot.com", "gotoOptions":{ "waitUntil": "networkidle2" }}' > test.pdf
Extra Headers
You can specify the page.setExtraHTTPHeaders options to add extra HTTP headers to the request that the TestingBot browser makes.
curl -X POST https://cloud.testingbot.com/pdf?key=YOUR_KEY&secret=YOUR_SECRET&browserName=chrome&version=latest&platform=WIN10 \
-H 'Content-Type: application/json' \
-d '{"url":"https://testingbot.com", "extraHeaders":{ 'foo': 'bar' }}' > test.pdf
Disable Javascript
You can disable Javascript with the page.setJavaScriptEnabled option.
curl -X POST https://cloud.testingbot.com/pdf?key=YOUR_KEY&secret=YOUR_SECRET&browserName=chrome&version=latest&platform=WIN10 \
-H 'Content-Type: application/json' \
-d '{"url":"https://testingbot.com", "javascriptEnabled":false}' > test.pdf
Emulate Media
Change the CSS media type of the page with page.emulateMediaType.