Convert Url to Pdf
This endpoint allows you to convert any publicly accessible Url into a Pdf.
GET
https://api.cloudlayer.io/v1/url/pdfMake a GET request to convert url to PDF, accepts simple options as query strings in URL (does not support advanced options).
POST
https://api.cloudlayer.io/v1/url/pdfMake a POST request to convert url to PDF, accepts advanced options in JSON body.
GET
/url/pdf
This endpoint is for simple URL to PDF requests that do not require advanced options, if you need advanced options you should use the POST method described below.
This endpoint supports a few configuration options specified in the table below. These options are passed into the method as URL query strings.
Param | Description |
---|---|
url (string) | Source URL to use for generating the PDF Required |
timeout (number) | Amount of time that Chrome is allowed to run, if exceeded your job will be terminated and you will not be charged. Default: 30000 ms (30 seconds) |
{ "url": "", "timeout": 30000 }
Copied!
Example
wget --header="X-API-Key: <api-key>" \ "https://api.cloudlayer.io/v1/url/pdf?url=https://google.com" \ -O google.jpg
Copied!
POST
/url/pdf
This endpoint allows full configuration options to be defined for converting a URL to a PDF.
Param | Description | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
url (string) | Source URL to use for generating the PDF Required | ||||||||||||||||||||||
timeout (number) | Amount of time that Chrome is allowed to run, if exceeded your job will be terminated and you will not be charged. Default: 30000 ms (30 seconds) | ||||||||||||||||||||||
delay (number) | The amount of time in milliseconds to wait for the page to complete rendering before conversion. Default: 0 | ||||||||||||||||||||||
filename (string) | If used with the inline:false, will set the Content-Disposition filename so that the downloaded file will be set to this value in the users browser. For inline:true it has no effect. Default: 'file.pdf' | ||||||||||||||||||||||
inline (boolean) | If set to true, set's the Content-Disposition to 'inline', if set to false it will set the Content-Disposition to 'attachment'. See 'filename' property if you want to set the filename value for the attachment. Default: false | ||||||||||||||||||||||
waitForSelector (waitForSelector) |
| ||||||||||||||||||||||
preferCSSPageSize (boolean) | Give any CSS @page size declared in the page priority over what is declared in width and height or format options. Default: false | ||||||||||||||||||||||
scale (boolean) | Scale of the webpage rendering. Defaults to 1. Scale amount must be between 0.1 and 2. Default: 1 | ||||||||||||||||||||||
height (string) | Paper height, accepts values labeled with units. Default: (empty) | ||||||||||||||||||||||
width (string) | Paper width, accepts values labeled with units. Default: (empty) | ||||||||||||||||||||||
landscape (boolean) | Paper orientation, false sets it to portrait and true to landscape. Default: false | ||||||||||||||||||||||
pageRanges (string) | Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages. Default: (empty" | ||||||||||||||||||||||
autoScroll (boolean) | Will attempt to auto scroll the page down to the very end. Useful for forcing lazy-loaded content to load. Default: false | ||||||||||||||||||||||
waitUntil (waitUntil) | When to consider navigation succeeded, defaults to networkidle2 Must be one one of the following values: load, domcontentloaded, networkidle0, networkidle2.
| ||||||||||||||||||||||
format (string) | Paper format to render the PDF. Must be one of the following values in the table below.
| ||||||||||||||||||||||
margin (margin) | Paper margins for top, bottom, right, left.
| ||||||||||||||||||||||
printBackground (boolean) | Print background graphics. Default: true | ||||||||||||||||||||||
headerTemplate (headerFooterTemplate) |
| ||||||||||||||||||||||
footerTemplate (headerFooterTemplate) |
|
{ "url": "", "timeout": 30000, "delay": 0, "filename": "file.pdf", "inline": false, "waitForSelector": { "selector": "", "options": { "visible": false, "hidden": false, "timeout": 0 } }, "preferCSSPageSize": false, "scale": 1, "height": "", "width": "", "landscape": false, "pageRanges": "", "autoScroll": false, "waitUntil": "networkidle2", "format": "Letter", "margin": { "bottom": "0.39in", "top": "0.4in", "left": "0.4in", "right": "0.39in" }, "printBackground": true, "headerTemplate": { "margin": { "bottom": "", "top": "", "left": "", "right": "" }, "style": "{ ...CssStyles }", "imageStyle": "{ ...CssStyles }", "method": "extract", "selector": "", "template": "" }, "footerTemplate": { "margin": { "bottom": "", "top": "", "left": "", "right": "" }, "style": "{ ...CssStyles }", "imageStyle": "{ ...CssStyles }", "method": "extract", "selector": "", "template": "" } }
Copied!
Example
wget --method POST \ --header 'X-API-Key: <api-key>' \ --header 'Content-Type: application/json' \ --body-data '{ "url": "https://en.wikipedia.org/wiki/Mark_Twain" }' \ https://api.cloudlayer.io/v1/url/pdf
Copied!