Free Support Forum - aspose.cloud

Convert PNG to PDF in Node.js with Aspose.PDF REST API

I am attempting to turn a png image into a pdf using the nodejs library for the cloud service.


I am attempting to use the PutCreate and GetImageSaveAs functions to convert an image to pdf and then save it. I have also tried with GetDownload and did not find that helpful.

What is happening is I am receiving an jpg image back instead of a pdf and the image has a red x going from corner to corner. Here is the code I am using.

storageApi.PutCreate(fileName, null, null, file.path, function(response) {
if (response.code !== 200) {
console.log(‘Uploading Error’, response.body)
return deferred.reject(‘Unable to upload document.’)
}
imagingApi.GetImageSaveAs(fileName, ‘pdf’, pdfName, null, null, function(response) {
if (response.code !== 200) {
console.log(‘Converting Error’, response.body.toString(‘utf8’))
return deferred.reject(‘Unable to convert document.’)
}
console.log(response.body)
var writeStream = fs.createWriteStream(pdfPlace);
writeStream.write(response.body);
deferred.resolve(pdfName);
});
});

Hi there,


Thanks for your inquiry. It seems you are trying to convert PNG to PDF using Aspose.Imaging for Clouds. Please note Aspose.Imaging does not supports image to PDF conversion. You need to use Aspose.Pdf for Clouds for the requirements. Please Check API Method for PNG to PDF conversion.

Please feel free to contact us for any further assistance.

Best Regards,