Reputation: 101
function convertToPDF() {
console.log("convertToPDF enters");
var pdfReactor = new PDFreactor("https://cloud.pdfreactor.com/service/rest");
console.log("convertToPDF enters 1");
var content = '<html><body><img src="/wps/wcm/myconnect/57444c38-84eb-4f37-b5c5-1dc901d400c0/1/logo.png?MOD=AJPERES&CACHEID=ROOTWORKSPACE-57444c38-84eb-4f37-b5c5-1dc901d400c0/1-lIeengm" alt="" title=""><br>'+document.getElementById("right-col").innerHTML+'</body></html>';
console.log("convertToPDF enters 2");
var config = {
'document': content,
}
pdfReactor.convert(config, function(result) {
console.log("convertToPDF enters 3");
document.getElementById("right-col").innerHTML += '<iframe id="result" style="display:none;"></iframe>';
document.getElementById("result").src = "data:application/pdf;base64," + result.document;
}
}
I need to convert html to pdf. for that I am using pdfreactor. I am able to generate pdf with body content which are actually text. but when I am trying to convert image apart from body. I am getting error.** Failed to load resource: the server responded with a status of 500 (Server Error)**. Basiclly I want to convert image to pdf.
Upvotes: 0
Views: 1092
Reputation: 301
The response code 500 likely indicates that the conversion time limit was reached. The PDFreactor Cloud Service for evaluation automatically terminates conversions if they take longer than 30 seconds. You could add an error handler in your code to get the full error message returned by the server:
pdfReactor.convert(config, function(result) {
//success
}, function(error) {
console.log(error)
};
Additionally, the image element in your source document contains a relative URL. Your HTML input is a string, in this case PDFreactor requires either an absolute image URL or an absolute base URL in order to resolve relative resource URLs against. So you could either change your image URL to an absolute one or specify an absolute base URL like this:
config = {
'document': content,
'baseURL': 'http://myServer/'
}
Upvotes: 0