PHP code example of groupdocscloud / conversion-sdk-php

1. Go to this page and download the library: Download groupdocscloud/conversion-sdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

groupdocscloud / conversion-sdk-php example snippets






O: Get your Client Id and a Client Secret at https://dashboard.groupdocs.cloud (free registration is XX-XXXXXXXXXXXX");
$configuration->setAppKey("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

$apiInstance = new GroupDocs\Conversion\ConvertApi($configuration);

try {
    // Prepare request
    $filePath = dirname(realpath(__DIR__)) . '/myFile.docx';
    $request = new Requests\ConvertDocumentDirectRequest("pdf", $filePath);

    // Convert
    $result = $apiInstance->convertDocumentDirect($request);

    // Done
    echo "Document converted: " . $result->getSize();
    echo "\n";
} catch (Exception $e) {
    echo  "Something went wrong: ",  $e->getMessage(), "\n";
    PHP_EOL;
}




O: Get your Client Id and a Client Secret at https://dashboard.groupdocs.cloud (free registration is XX-XXXXXXXXXXXX");
$configuration->setAppKey("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

$fileApi = new GroupDocs\Conversion\FileApi($configuration);
$convertApi = new GroupDocs\Conversion\ConvertApi($configuration);

try {
    // Upload file to cloud storage
    $putCreateRequest = new \GroupDocs\Conversion\Model\Requests\uploadFileRequest('myFile.docx', './myFile.docx');
    $putCreateResponse = $fileApi->uploadFile($putCreateRequest);

    // Convert
    $settings = new \GroupDocs\Conversion\Model\ConvertSettings();
    $settings->setFilePath('myFile.docx');
    $settings->setFormat("pdf");
    $settings->setOutputPath("converted");
    $result = $convertApi->convertDocument(new \GroupDocs\Conversion\Model\Requests\ConvertDocumentRequest($settings));
    echo "Document converted: " . $result[0]->getUrl();
    echo "\n"; 
    
    // Download converted document
    $request = new GroupDocs\Conversion\Model\Requests\DownloadFileRequest("converted/myFile.pdf", null, null);
    $response = $fileApi->downloadFile($request);  
    echo "Expected response type is File: ", strlen($response);

} catch (Exception $e) {
    echo  "Something went wrong: ",  $e->getMessage(), "\n";
    PHP_EOL;
}