This function will generate a PDF of the page you specified and return the PDF file.
Basic Example
curl -X POST \
"https://chrome.headlesstesting.com/pdf?token=[YOUR-TOKEN]" \
-H 'Content-Type: application/json' \
-d '{"url":"https://headlesstesting.com"}' > test.pdf
This simple example will run a Puppeteer script on our service and do the following:
- Start a Headless Chrome Browser (latest version) on our cloud
- Connect with Puppeteer to the Headless Browser and navigate to the URL you specified
- Generate a PDF from the page
-
Return the
PDF file
back to you
Options
You can specify additional options with this function call to customize the PDF taking.
Puppeteer PDF options
This function call can use any of the Puppeteer page.pdf options.
curl -X POST \
"https://chrome.headlesstesting.com/pdf?token=[YOUR-TOKEN]" \
-H 'Content-Type: application/json' \
-d '{"url":"https://headlesstesting.com", "options":{"fullPage":true}}' > test.pdf
Authenticate options
You can specify the page.authenticate credentials.
curl -X POST \
"https://chrome.headlesstesting.com/pdf?token=[YOUR-TOKEN]" \
-H 'Content-Type: application/json' \
-d '{"url":"https://headlesstesting.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://chrome.headlesstesting.com/pdf?token=[YOUR-TOKEN]" \
-H 'Content-Type: application/json' \
-d '{"url":"https://headlesstesting.com", "gotoOptions":{ "waitUntil": "networkidle2" }}' > test.pdf
Extra Headers
You can specify the page.setExtraHTTPHeaders options to add extra HTTP headers to the request our Headless Browser makes.
curl -X POST \
"https://chrome.headlesstesting.com/pdf?token=[YOUR-TOKEN]" \
-H 'Content-Type: application/json' \
-d '{"url":"https://headlesstesting.com", "extraHeaders":{ 'foo': 'bar' }}' > test.pdf
Disable Javascript
You can disable Javascript with the page.setJavaScriptEnabled option.
curl -X POST \
"https://chrome.headlesstesting.com/pdf?token=[YOUR-TOKEN]" \
-H 'Content-Type: application/json' \
-d '{"url":"https://headlesstesting.com", "javascriptEnabled":false}' > test.pdf
Emulate Media
Change the CSS media type of the page with page.emulateMediaType.
curl -X POST \
"https://chrome.headlesstesting.com/pdf?token=[YOUR-TOKEN]" \
-H 'Content-Type: application/json' \
-d '{"url":"https://headlesstesting.com", "emulateMedia":"print"}' > test.pdf