PHP PDF to HTML creating corrupt ZIP files?

I followed the example (http://saaspose.com/docs/display/pdf/Convert+PDF+documents+to+HTML+(PHP+REST)) on how to convert PDF’s to HTML verbatim, but it is creating a corrupt ZIP file, which means that the HTML files are not outputted.

My full code:

<?php error_reporting(E_ALL | E_STRICT); ini_set('display_errors', 'On'); require_once("sdk/saaspose.php"); SaasposeApp::$AppSID = "159e7510-5edd-4ad8-9e87-a77de335859e"; SaasposeApp::$AppKey = "3b76b46c17956179bd5173174d4dba86"; $BaseProductUri = "http://api.saaspose.com/v1.0"; SaasposeApp::$OutPutLocation = getcwd() . "/Output/"; $fileName = "input.pdf"; echo "Converting PDF to HTML...
"; $strURI = Product::$BaseProductUri . "/pdf/" . $fileName . "?format=html"; $signedURI = Utils::Sign($strURI); $responseStream = Utils::processCommand($signedURI, "GET", "", ""); $v_output = Utils::ValidateOutput($responseStream); if ($v_output === "") { $outputPath = SaasposeApp::$OutPutLocation . Utils::getFileName($fileName). ".zip"; Utils::saveFile($responseStream, $outputPath); system('unzip -q '. $outputPath .' -d '. getcwd() . "/Output/OutputHtml"); echo "File converted"; } ?>

I’ve attached the PDF file being used below:

Hi,

Sorry, I was unable to reproduce this issue at my end. I copied your code and added following two extra lines to upload input file:

$folder = new Folder();
$folder->UploadFile(getcwd() . "\\Input\\" . $fileName, "");

and the file was converted to HTML.

Can you please confirm if you had uploaded the input PDF file before running this code? If yes, please share what is in the $signedURI variable. At my end, it was http://api.saaspose.com/v1.0/pdf/input.pdf?format=html&appSID=159e7510-5edd-4ad8-9e87-a77de335859e&signature=I5zTA_K-GBPAIijy5T4bd6ZRMso= and you can copy this URI in your browser's address bar to check the result.

Best Regards,
Muhammad Ijaz

Support Developer, Saaspose Sialkot Team
http://www.saaspose.com

Will using that upload code upload the document to the storage when running the script?

Sent from my iPad

Hi,

Yes, it will upload input file to Saaspose storage. You can also use the following code if you do not want to upload file to Saaspose or any other storage.

SaasposeApp::$AppSID = "159e7510-5edd-4ad8-9e87-a77de335859e";
SaasposeApp::$AppKey = "3b76b46c17956179bd5173174d4dba86";
$BaseProductUri = "http://api.saaspose.com/v1.0";
SaasposeApp::$OutPutLocation = getcwd() . "/Output/";

$fileName = "input.pdf";

echo "Converting PDF to HTML...
";

$strURI = Product::$BaseProductUri . "/pdf/convert?format=html";

$signedURI = Utils::Sign($strURI);

$responseStream = Utils::uploadFileBinary($signedURI, getcwd() . "/Input/" . $fileName , "xml");

$v_output = Utils::ValidateOutput($responseStream);

if ($v_output === "")
{
$outputPath = SaasposeApp::$OutPutLocation . Utils::getFileName($fileName). ".zip";
Utils::saveFile($responseStream, $outputPath);
system('unzip -q '. $outputPath .' -d '. getcwd() . "/Output/OutputHtml");

echo "File converted";
}

Best Regards,
Muhammad Ijaz

Support Developer, Saaspose Sialkot Team
http://www.saaspose.com

Hi Charles,

Did the last suggestion from our support team help you? Do you need any further assistance while working with Saaspose API? If you need any further help, please do let us know. We'll be glad to help you.

Thanks & Regards
Shahzad Latif
Saaspose Support Team.