I’m looking to test pdfshit in my Wix website but cannot find a template to work with. Is there anything out there that I can try? The developers of the library gave me the following script, which gave me an error (Parsing error: Unexpected token) in the install line. I’m not sure where the problem is and how to fix it:
// For full API documentation, including code examples, visit https: //wix.to/94BuAAs
$w.onReady( function () {
// usage:
// pdfshift({‘source’: ‘PDF - Wikipedia’, ‘use_print’: true}, ‘your_api_key’).then(…)
function pdfshift(data, apiKey) {
/**
* Javascript function for PDFShift
* @param apiKey: Your API key from PDFShift. Optional. Can be null
* @param data: Parameters to send to PDFShift. Must contains at least the “source”
*/
return new Promise( function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open(‘POST’, ‘https://api.pdfshift.io/v2/convert/’, true );
xhr.setRequestHeader(“Content-Type”, “application/json”);
if (apiKey) {
xhr.setRequestHeader(‘Authorization’, 'Basic ’ + btoa(apiKey + ‘:’));
}
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
// The request was successful!
// The xhr.responseText contains the PDF
resolve(xhr.responseText);
} else {
// An error occured!
var json = JSON.parse(xhr.responseText);
reject(json);
}
}
};
xhr.send(JSON.stringify(data));
});
}