phpcloudconvert

Class not found error when using CloudConvert to combine PDFs using PHP


I am trying to combine 3 PDFs into one using CloudConvert. I followed the examples on their website, but I keep getting an Class 'net\websitename\libraries\CloudConvert\Api' not found error. I am stumped as to how to proceed from here.

Here is my code:

public function combineInvoiceVoucherList($jobid) {
    // Using their files for testing
    $file1 = 'https://cloudconvert.com/assets/e214b299/testfiles/pdfexample1.pdf';
    $file2 = 'https://cloudconvert.com/assets/e214b299/testfiles/pdfexample2.pdf';
    require APPPATH . 'libraries/CloudConvert.class.php';

    $api = new Api('apikey');

    $process = $api->createProcess([
        'mode' => 'combine',
        'inputformat' => 'pdf',
        'outputformat' => 'pdf',
    ]);
    $process->start([
        'mode' => 'combine',
        'input' => 'download',
        'files' => [
            '0' => $file1,
            '1' => $file2,
        ],
        'outputformat' => 'pdf',
        'wait' => true,
    ]);
    $process->download('testingdownload.pdf');
}

I tried using:

require __DIR__ . '/vendor/autoload.php';
use \CloudConvert\Api;

$api = new Api('apikey');

$process = $api->createProcess([
    "mode" => "combine",
    "inputformat" => "pdf",
    "outputformat" => "pdf",
]);

but that just got me a 404 Page Not Found error.

I am very new at this, so any help would be much appreciated.


Solution

  • I have other errors now, but this is what I tried and it solved the class not found error.

    use net\websitename\libraries\CloudConvert\CloudConvert;
    
    public function combineInvoiceVoucherList($jobid) {
        $file1 = 'https://cloudconvert.com/assets/e214b299/testfiles/pdfexample1.pdf';
        $file2 = 'https://cloudconvert.com/assets/e214b299/testfiles/pdfexample2.pdf';
        require APPPATH . 'libraries/CloudConvert.class.php';
    
        $api = new CloudConvert();
    
        $apikey = 'apikey';
    
        $process = CloudConvert::createProcess('pdf', 'pdf', $apikey);
        $this->session->set_flashdata('message', 'File combination started - reload job to view.');
        redirect('job/editjob/' . $jobid);
    }