codeinc / cloudrun-gotenberg
Wrapper to use the Gotenberg HTTP client library with a CloudRun service
Requires
- php: >=8.2
- codeinc/cloudrun-auth-http-client: ^1.1
- gotenberg/gotenberg-php: ^2.0
Requires (Dev)
README
The PHP 8.2+ library provides an authenticated Gotenberg client using codeinc/cloudrun-auth-http-client
to be used with a Gotenberg service running on Google Cloud Platform Cloud Run.
Installation
The library is available on Packagist. You can install it using Composer:
composer require codeinc/cloudrun-gotenberg
Usage
This library is modeled after the official Gotenberg PHP client. The methods of the class CodeInc\CloudRunGotenberg\CloudRunGotenberg
are the same as the Gotenberg\Gotenberg
class (but they are not static
).
The requests are authenticated using codeinc/cloudrun-auth-http-client
. A service account is required to authenticate the requests. Check this page to learn how to create and authorized a service account and obtain the service account key.
The following conversion examples are extracted from Gotenberg PHP client documentation.
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) ) );
License
The library is published under the MIT license (see LICENSE
file).