PHP code example of convertapi / convertapi-php

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

    

convertapi / convertapi-php example snippets




use \ConvertApi\ConvertApi;

ConvertApi::setApiSecret('your-api-secret');

$result = ConvertApi::convert('pdf', ['File' => '/path/to/my_file.docx']);

# save to file
$result->getFile()->save('/path/to/save/file.pdf');

# get file contents (without saving the file locally)
$contents = $result->getFile()->getContents();

# save all result files to folder
$result->saveFiles('/path/to/save/files');

# get conversion cost
$cost = $result->getConversionCost();

$result = ConvertApi::convert('pdf', ['File' => 'https://website/my_file.docx']);

$result = ConvertApi::convert(
    'pdf',
    ['File' => '/path/to/my_file'],
    'docx'
);

$result = ConvertApi::convert(
    'pdf',
    [
        'File' => '/path/to/my_file.docx',
        'PageRange' => '1-10',
        'PdfResolution' => '150',
    ]
);

$info = ConvertApi::getUser();

echo $info['SecondsLeft'];

ConvertApi::setApiBase('https://eu-v2.convertapi.com/');