kitlabs-cn / gotenberg-php-client
A client for sending files to a Gotenberg API
3.1.1
2018-12-18 14:50 UTC
Requires
- php: >=7.1
- guzzlehttp/psr7: ^1.4.2
- php-http/client-implementation: ^1.0
- php-http/discovery: ^1.0
- php-http/httplug: >=1.0
- php-http/message: ^1.0
- psr/http-message: ^1.0
- thecodingmachine/safe: ^0.1.8
Requires (Dev)
- php-http/guzzle6-adapter: ^1.1
- php-http/mock-client: ^1.0
- phpstan/phpstan: ^0.10.5
- phpunit/phpunit: ^7
- squizlabs/php_codesniffer: ^3.2
- thecodingmachine/phpstan-safe-rule: ^0.1.0
- thecodingmachine/phpstan-strict-rules: ^0.10.7
This package is not auto-updated.
Last update: 2024-11-14 18:30:41 UTC
README
A simple PHP client for interacting with a Gotenberg API.
Install
Unless your project already have a PSR7 HttpClient
, install php-http/guzzle6-adapter
:
$ composer require php-http/guzzle6-adapter
Then the PHP client:
$ composer require thecodingmachine/gotenberg-php-client
Usage
<?php namespace YourAwesomeNamespace; use TheCodingMachine\Gotenberg\Client; use TheCodingMachine\Gotenberg\ClientException; use TheCodingMachine\Gotenberg\DocumentFactory; use TheCodingMachine\Gotenberg\HTMLRequest; use TheCodingMachine\Gotenberg\Request; use TheCodingMachine\Gotenberg\RequestException; class YourAwesomeClass { public function yourAwesomeMethod() { $client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); # or the following if you want the client to discover automatically an installed implementation of the PSR7 `HttpClient`. $client = new Client('http://localhost:3000'); # HTML conversion example. $index = DocumentFactory::makeFromPath('index.html', '/path/to/file'); $header = DocumentFactory::makeFromPath('header.html', '/path/to/file'); $footer = DocumentFactory::makeFromPath('footer.html', '/path/to/file'); $assets = [ DocumentFactory::makeFromPath('style.css', '/path/to/file'), DocumentFactory::makeFromPath('img.png', '/path/to/file'), ]; try { $request = new HTMLRequest($index); $request->setHeader($header); $request->setFooter($footer); $request->setAssets($assets); $request->setPaperSize(Request::A4); $request->setMargins(Request::NO_MARGINS); # store method allows you to... store the resulting PDF in a particular folder. # this method also returns the resulting PDF path. $filePath = $client->store($request, 'path/to/folder/you/want/the/pdf/to/be/store'); # if you wish to redirect the response directly to the browser, you may also use: $response = $client->post($request); } catch (RequestException $e) { # this exception is thrown if given paper size or margins are not correct. } catch (ClientException $e) { # this exception is thrown by the client if the API has returned a code != 200. } catch (\Exception $e) { # some (random?) exception. } } }
For more complete usages, head to the documentation.