PHP code example of codeinc / cloudrun-gotenberg

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

    

codeinc / cloudrun-gotenberg example snippets


use CodeInc\CloudRunGotenberg\CloudRunGotenberg;
use Gotenberg\Stream;

// Creates the Cloud Run Gotenberg client 
$cloudRunGotenberg = new CloudRunGotenberg(
    // Cloud Run service URL
    'https://my-service-12345-uc.a.run.app',
    // path to your service account key or array of credentials 
    '/path/to/your/service-account-key.json' 
);

// Converts a target URL to PDF and saves it to a given directory.
$filename = $cloudRunGotenberg->save(
    $cloudRunGotenberg->chromium()->pdf()->url('https://my.url'), 
    $pathToSavingDirectory
);

// Converts Office documents to PDF and merges them.
$response = $cloudRunGotenberg->send(
    $cloudRunGotenberg->libreOffice()
        ->merge()
        ->convert(
            Stream::path($pathToDocx),
            Stream::path($pathToXlsx)
        )
);