Free Support Forum - aspose.cloud

PDF to JPEG Conversion issue in PHP

This post was flagged by the community and is temporarily hidden.

@administrator1

Thanks for your inquiry. It seems you are using quite old Base URI. Please use https://api.aspose.cloud/v3.0 instead of https://api.aspose.com/v1.1. Furthermore, I have tested the PostDocumentSaveAs API with your sample PDF document and unable to notice any issue. Please check sample code below. Please also check Aspose.PDF Cloud SDK for PHP for more details.

Please note Aspose.PDF Cloud API Version 3.0 provides its own methods for storage operations. Now there is no need to use Aspose.Storage Cloud API for the purpose.

<?php

require_once('C:\xampp\htdocs\aspose-pdf-cloud-php-master\vendor\autoload.php');

use Aspose\PDF\Api\PdfApi;
use Aspose\PDF\Configuration;

//TODO: Get your AppSID and AppKey at https://dashboard.aspose.cloud (free registration is required).

$configuration = new Configuration();
$configuration->setAppSid("xxxxx-xxxx-xxxx-xxxx-xxxxxxxx");
$configuration->setAppKey("xxxxxxxxxxxxxxxxxxx");

$pdfApi = new PdfApi(null,$configuration); 

try {	

        $name = "Jan newsletter.pdf";
        $page_number = 2;
        $result_file = "page2.jpeg";
        $folder="Temp";
		$out_path = "$folder/$result_file";
        $response = $pdfApi->putPageConvertToJpeg($name, $page_number, $out_path, $width = null, $height = null, $folder);        
	print_r($response);
	echo "Completed!!!!";
    
} catch (Exception $e) {
    echo  "Something went wrong: ",  $e->getMessage(), "\n";
    PHP_EOL;
}

?>

I have updated the base URL to 3.0 however I am still seeing the error: “An error occurred while sending the request.”

I will include a second file that I am experiencing the error with when I try to convert page 1 of the .pdf to a .jpeg. I am not seeing how I can determine more detail on what the error is?

Here’s links to the two files that are failing:


Out of curiosity, I used this tool: pdfresizer.com

and when I do that the .pdf file converts just fine to an image using your API. So, I believe there is something about the two file attachments that your API is failing at. That is, the parser code on your server is choking in some way.

@administrator1

We are sorry for your inconvenience. Can you please check and share the error details from the My Usage tab of your aspose.cloud dashboard ?

I just went to that screen and I do not see an errors. However, when everything works properly, I see ths following:

01/09/2020 5:18 PM Default App storage Success: Remove the file… path ‘lisacourtpricedropresizepdf’,versionId ‘’,storage ‘’ 1,812,367.00 kb 50.28.8.219
01/09/2020 5:18 PM Default App pdf Success: Convert document page to Png image and return resulting file in response… name ‘lisacourtpricedropresizepdf’,pageNumber ‘1’,width ‘800’,height ‘’,folder ‘’,storage ‘’ 1,812,367.00 kb 50.28.8.219
01/09/2020 5:18 PM Default App storage Success: Upload the file… path ‘lisacourtpricedropresizepdf’,versionId ‘’,storage ‘’

however, when I have a failure, I get the following:

01/09/2020 5:16 PM Default App storage Success: Upload the file… path ‘lisacourtpricedropresizepdf’,versionId ‘’,storage ‘’ n/a 50.28.8.219
01/09/2020 5:13 PM Default App storage Success: Remove the file… path ‘lisacourtpricedroppdf’,versionId ‘’,storage ‘’ 10,640,572.00 kb 50.28.8.219

where the conversion step is simply missing! So, no error, but refusal to do the operation.

thanks,

Scott.

for failure, here’s the pair of entries I see:

01/09/2020 5:13 PM Default App storage Success: Remove the file… path ‘lisacourtpricedroppdf’,versionId ‘’,storage ‘’ 10,640,572.00 kb 50.28.8.219
01/09/2020 5:13 PM Default App storage Success: Upload the file… path ‘lisacourtpricedroppdf’,versionId ‘’,storage ‘’

@administrator1

As per your log, it seems only Aspose.Storage Cloud API calls are working for you.

As suggested above please use latest Aspose.PDF Cloud SDK for PHP, it includes its own API methods for storage.

Furthermore, please note V3.0 uses JSON Web Token(JWT) for authenticating API requests. If you are not using Aspose.PDF SDK for PHP then please double check you are using JWT correctly.