codeinc / cloudrun-gotenberg
用于使用 CloudRun 服务与 Gotenberg HTTP 客户端库包装器
v1.4
2024-02-17 00:57 UTC
Requires
- php: >=8.2
- codeinc/cloudrun-auth-http-client: ^1.1
- gotenberg/gotenberg-php: ^2.0
Requires (Dev)
README
PHP 8.2+ 库使用 codeinc/cloudrun-auth-http-client
提供了认证的 Gotenberg 客户端,用于与在 Google Cloud Platform Cloud Run 上运行的 Gotenberg 服务一起使用。
安装
该库可在 Packagist 上找到。您可以使用 Composer 进行安装。
composer require codeinc/cloudrun-gotenberg
用法
该库是基于 官方 Gotenberg PHP 客户端 设计的。类 CodeInc\CloudRunGotenberg\CloudRunGotenberg
的方法与类 Gotenberg\Gotenberg
相同(但它们不是 static
)。
请求使用 codeinc/cloudrun-auth-http-client
进行认证。需要服务帐户来认证请求。请查阅此页面了解如何创建和授权服务帐户以及获取服务帐户密钥。
以下转换示例是从 Gotenberg PHP 客户端文档 中提取的。
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) ) );
许可证
该库根据 MIT 许可证发布(见 LICENSE
文件)。