Skip to content

API Merge

damiancosmoschapman edited this page Oct 5, 2021 · 11 revisions

Home / API / Merge JSON-RPC

This page contains the JSON-RPC versions of the Create method for merging to a PDF from multiple URLs. For the RESTful method, please go to the Merge RESTful for Merge.

Create a PDF file from merging multiple CSO domain URLs.

Returns a base64 PDF string

Authentication: Anonymous

Privilege : N/A

Method: PDFapi.Data.Convert_API.Create

Parameters:

Name Type Default Description
urls Array[string] null or empty URLs to convert to PDF
chromeCommandLineOptions Array[string] *see below Chrome Command Line Options
printOptions JSON Object **see below Print Options
htmlIdsToCut Array[string] null or empty HTML Ids to filter out of URLs
htmlIdForMasterHeader string null or empty HTML Id to use as the master header on the first page of the PDF
htmlIdForMasterFooter string null or empty HTML Id to use as the master footer on the last page of the PDF
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",
      "https://www.cso.ie/en/indexpdf.html" ],
      "htmlIdsToCut": ["header", "footer"],
      "htmlIdForMasterHeader": "header",
      "htmlIdForMasterFooter": "footer",
      "chromeCommandLineOptions":[
         "headless",
         "disable-gpu",
         "run-all-compositor-stages-before-draw"
      ],
      "printOptions":{
         "paperWidth":8.3,
         "PaperWidth": 4.4,
         "paperHeight":11.7,
         "scale":1.0,
         "pageRanges":"1",
         "printBackground":true
      },
      "returnType":"base64String"
   }
}

Return: json

The Json format follow the JSON-Stat schema. Please refer to JSON-stat documentation. An example is shown below:

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