PHP code example of cloudpdf / sdk

1. Go to this page and download the library: Download cloudpdf/sdk 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/ */

    

cloudpdf / sdk example snippets




namespace Example;

use CloudPDF\CloudPDFClient;
use CloudPDF\Shares\Requests\SharesExchangeRequest;

$client = new CloudPDFClient(
    token: '<token>',
);
$client->shares->exchange(
    new SharesExchangeRequest([
        'shareToken' => 'shareToken',
    ]),
);


use CloudPDF\Exceptions\CloudPDFApiException;
use CloudPDF\Exceptions\CloudPDFException;

try {
    $response = $client->shares->exchange(...);
} catch (CloudPDFApiException $e) {
    echo 'API Exception occurred: ' . $e->getMessage() . "\n";
    echo 'Status Code: ' . $e->getCode() . "\n";
    echo 'Response Body: ' . $e->getBody() . "\n";
    // Optionally, rethrow the exception or handle accordingly.
}

use CloudPDF\CloudPDFClient;

// Pass any PSR-18 compatible HTTP client implementation.
// For example, using Guzzle:
$customClient = new \GuzzleHttp\Client([
    'timeout' => 5.0,
]);

$client = new CloudPDFClient(options: [
    'client' => $customClient
]);

// Or using Symfony HttpClient:
// $customClient = (new \Symfony\Component\HttpClient\Psr18Client())
//     ->withOptions(['timeout' => 5.0]);
//
// $client = new CloudPDFClient(options: [
//     'client' => $customClient
// ]);

$response = $client->shares->exchange(
    ...,
    options: [
        'maxRetries' => 0 // Override maxRetries at the request level
    ]
);

$response = $client->shares->exchange(
    ...,
    options: [
        'timeout' => 3.0 // Override timeout at the request level
    ]
);