Skip to content

API Convert

damiancosmoschapman edited this page Oct 5, 2021 · 16 revisions

Home / API / Convert JSON-RPC

This page contains the JSON-RPC versions of the Create method for converting to a PDF from a URL. For the RESTful method, please go to the RESTful page for Convert.

Create a PDF file from a CSO domain URL.

Returns a base64 PDF string

Authentication: Anonymous

Privilege : N/A

Method: PDFapi.Data.Convert_API.Create

Parameters:

Name Type Default Description
urls string null or empty URL to convert to PDF
chromeCommandLineOptions Array[string] *see below Chrome Command Line Options
printOptions JSON Object **see below Print Options
returnType string byteArray Return type of API

*The default value for the chromeCommandLineOptions are:

{
    "chromeCommandLineOptions":[
       "headless",
       "disable-gpu",
       "run-all-compositor-stages-before-draw"
    ]
}

The full list of chromeCommandLineOptions are available here: https://peter.sh/experiments/chromium-command-line-switches

**The default value for the printOptions are:

{
   "printOptions":{
      "landscape":false,
      "displayHeaderFooter":false,
      "printBackground":false,
      "scale":1,
      "paperWidth":8.5,
      "paperHeight":11,
      "marginTop":1,
      "marginBottom":1,
      "marginLeft":1,
      "marginRight":1,
      "pageRanges":"",
      "ignoreInvalidPageRanges":false,
      "headerTemplate":"",
      "footerTemplate":"",
      "preferCSSPageSize":false
   }
}

The full list of printOptions are available here: https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF

POST Body: json

An example is shown below:

{
   "jsonrpc":"2.0",
   "method":"PDFapi.Data.Convert_API.Create",
   "params":{
      "urls": [ "https://data.cso.ie" ],
      "chromeCommandLineOptions":[
         "headless",
         "disable-gpu",
         "run-all-compositor-stages-before-draw"
      ],
      "printOptions":{
         "paperWidth":8.3,
         "paperHeight":11.7,
         "scale":1.0,
         "pageRanges":"1"
      },
    "returnType":"base64String"
   },
   "id": 123
}

Return: json

An example is shown below:

{
    "jsonrpc": "2.0",
    "result": "data:application/pdf;base64,JVBERi0xLjQKJdPr6eEKMSAwIG9iago8PC9DcmVhdG9yIChDaHJvbWl1bSkKL1Byb..."    
    "id": "123"
}
Clone this wiki locally