link

PrintCSS

How do I change the rendering tool for my request?

The PrintCSS Cloud API offers the three rendering tools WeasyPrint (default), PagedJS, and Vivliostyle. If you want to change the rendering tool for your REST request, all you need to do is provide the renderer's name within the options section of the requests JSON.

{
    "html": "<h1>Hello PrintCSS Cloud!</h1>",
    "css": "h1 { color: blue; }",
    "options": {
        "renderer": "vivliostyle"
    }
}

As you see in the above request body, the renderer needs to be provided in lowercase.

To send the request to our API now, you need to subscribe to a plan on RapidAPI. With this, you get the API key that is required to authenticate with our REST service.

A sample cURL request would look like this:

curl --location --request POST 'https://printcss-cloud.p.rapidapi.com/render' \
--header 'x-rapidapi-host: printcss-cloud.p.rapidapi.com' \
--header 'x-rapidapi-key: YOUR_API_KEY' \
--data-raw '{
    "html": "<h1>Hello PrintCSS Cloud!</h1>",
    "css": "h1 { color: blue; }",
    "options": {
        "renderer": "vivliostyle"
    }
}'

The PHP request:

<?php

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => 'https://printcss-cloud.p.rapidapi.com/render',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS =>'{
        "html": "<h1>Hello PrintCSS Cloud!</h1>",
        "css": "h1 { color: blue; }",
        "options": {
            "renderer": "vivliostyle"
        }
    }',
    CURLOPT_HTTPHEADER => [
        'x-rapidapi-host: printcss-cloud.p.rapidapi.com',
        'x-rapidapi-key: YOUR_API_KEY'
    ],
]);

$response = curl_exec($curl);

curl_close($curl);
echo $response;

and a sample JavaScript request:

var data = "{\r\n    \"html\": \"<h1>Hello PrintCSS Cloud!</h1>\",\r\n    \"css\": \"h1 { color: blue; }\",\r\n    \"options\": {\r\n        \"renderer\": \"vivliostyle\"\r\n    }\r\n}";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", () => {
    if (4 === this.readyState) {
        console.log(this.responseText);
    }
});

xhr.open("POST", "https://printcss-cloud.p.rapidapi.com/render");
xhr.setRequestHeader("x-rapidapi-host", "printcss-cloud.p.rapidapi.com");
xhr.setRequestHeader("x-rapidapi-key", "YOUR_API_KEY");

xhr.send(data);

The result of the above API request can be found in the attachment below.

pdf rendered with vivliostyle (PDF, 7.11 KB)