PHP code example of thecodingmachine / gotenberg-php-client
1. Go to this page and download the library: Download thecodingmachine/gotenberg-php-client 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/ */
thecodingmachine / gotenberg-php-client example snippets
use TheCodingMachine\Gotenberg\Client;
use TheCodingMachine\Gotenberg\ClientException;
use TheCodingMachine\Gotenberg\DocumentFactory;
use TheCodingMachine\Gotenberg\HTMLRequest;
use TheCodingMachine\Gotenberg\Request;
use TheCodingMachine\Gotenberg\RequestException;
use GuzzleHttp\Psr7\LazyOpenStream;
# create the client.
$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');
# prepare the files ', '/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);
$request->setScale(0.75);
# store method allows you to... store the resulting PDF in a particular destination.
$client->store($request, 'path/you/want/the/pdf/to/be/stored.pdf');
# if you wish to redirect the response directly to the browser, you may also use:
$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.
}
bash
$ composer