1- <h3 align =" center " >Gotenberg PHP Client</h3 >
2- <p align =" center " >A PHP client for the Gotenberg API</p >
3- <p align =" center " >
4- <a href="https://travis-ci.org/thecodingmachine/gotenberg-php-client">
5- <img src="https://travis-ci.org/thecodingmachine/gotenberg-php-client.svg?branch=master" alt="Travis CI">
6- </a>
7- <a href="https://scrutinizer-ci.com/g/thecodingmachine/gotenberg-php-client/?branch=master">
8- <img src="https://scrutinizer-ci.com/g/thecodingmachine/gotenberg-php-client/badges/quality-score.png?b=master" alt="Scrutinizer">
9- </a>
10- <a href="https://codecov.io/gh/thecodingmachine/gotenberg-php-client/branch/master">
11- <img src="https://codecov.io/gh/thecodingmachine/gotenberg-php-client/branch/master/graph/badge.svg" alt="Codecov">
12- </a>
13- </p >
1+ # Gotenberg PHP client
142
15- ---
16-
17- [ Gotenberg] ( https://github.com/thecodingmachine/gotenberg ) is a stateless API for converting Markdown files, HTML files and Office documents to PDF.
18- This package helps you to interact with this API using PHP.
19-
20- # Menu
21-
22- * [ Install] ( #install )
23- * [ Docker] ( #docker )
24- * [ Usage] ( #usage )
3+ A simple PHP client for interacting with a Gotenberg API.
254
265## Install
276
@@ -37,31 +16,6 @@ Then the PHP client:
3716$ composer require thecodingmachine/gotenberg-php-client
3817```
3918
40- ## Docker
41-
42- As the [ Gotenberg] ( https://github.com/thecodingmachine/gotenberg ) API is provided within a Docker image, you'll have to add it
43- to your Docker Compose stack:
44-
45- ``` yaml
46- version : ' 3'
47-
48- services :
49-
50- # your others services
51-
52- gotenberg :
53- image : thecodingmachine/gotenberg:2.0.0
54- ` ` `
55-
56- You may now start your stack using:
57-
58- ` ` ` bash
59- $ docker-compose up --scale gotenberg=your_number_of_instances
60- ```
61-
62- When requesting the Gotenberg service with your client, Docker will automatically redirect a request to a Gotenberg container
63- according to the round-robin strategy.
64-
6519## Usage
6620
6721``` php
@@ -72,8 +26,9 @@ namespace YourAwesomeNamespace;
7226use TheCodingMachine\Gotenberg\Client;
7327use TheCodingMachine\Gotenberg\ClientException;
7428use TheCodingMachine\Gotenberg\DocumentFactory;
75-
76- use GuzzleHttp\Psr7\LazyOpenStream;
29+ use TheCodingMachine\Gotenberg\HTMLRequest;
30+ use TheCodingMachine\Gotenberg\Request;
31+ use TheCodingMachine\Gotenberg\RequestException;
7732
7833class YourAwesomeClass {
7934
@@ -83,39 +38,47 @@ class YourAwesomeClass {
8338 # or the following if you want the client to discover automatically an installed implementation of the PSR7 `HttpClient`.
8439 $client = new Client('gotenberg:3000');
8540
86- # let's instantiate some documents you wish to convert.
87- $yourOfficeDocument = DocumentFactory::makeFromPath('file.docx', '/path/to/file');
88- $yourHTMLDocument = DocumentFactory::makeFromStream('file.html', new LazyOpenStream('path/to/file', 'r'));
41+ # HTML conversion example.
42+ $index = DocumentFactory::makeFromPath('index.html', '/path/to/file');
43+ $header = DocumentFactory::makeFromPath('header.html', '/path/to/file');
44+ $footer = DocumentFactory::makeFromPath('footer.html', '/path/to/file');
45+ $assets = [
46+ DocumentFactory::makeFromPath('style.css', '/path/to/file'),
47+ DocumentFactory::makeFromPath('img.png', '/path/to/file'),
48+ ];
8949
90- # now let's send those documents!
9150 try {
51+ $request = new HTMLRequest($index);
52+ $request->setHeader($header);
53+ $request->setFooter($footer);
54+ $request->setAssets($assets);
55+ $request->setPaperSize(Request::A4);
56+ $request->setMargins(Request::NO_MARGINS);
57+
9258 # store method allows you to... store the resulting PDF in a particular folder.
9359 # this method also returns the resulting PDF path.
94- $filePath = $client->store([
95- $yourOfficeDocument,
96- $yourHTMLDocument
97- ], 'path/to/folder/you/want/the/pdf/to/be/store');
60+ $filePath = $client->store($request, 'path/to/folder/you/want/the/pdf/to/be/store');
9861
9962 # if you wish to redirect the response directly to the browser, you may also use:
100- $response = $client->forward([
101- $yourOfficeDocument,
102- $yourHTMLDocument
103- ]);
63+ $response = $client->post($request);
10464
65+ } catch (RequestException $e) {
66+ # this exception is thrown is given paper size or margins are not correct.
10567 } catch (ClientException $e) {
10668 # this exception is thrown by the client if the API has returned a code != 200.
10769 } catch (\Http\Client\Exception $e) {
10870 # some PSR7 exception.
10971 } catch (\Exception $e) {
11072 # some (random?) exception.
11173 }
112- }
113-
74+ }
11475}
11576```
11677
117- Voilà! : smiley :
78+ For more complete usages, head to the [ documentation ] ( https://thecodingmachine.github.io/gotenberg ) .
11879
119- ---
80+ ## Badges
12081
121- Would you like to update this documentation ? Feel free to open an [ issue] ( ../../issues ) .
82+ [ ![ Travis CI] ( https://travis-ci.org/thecodingmachine/gotenberg-php-client.svg?branch=master )] ( https://travis-ci.org/thecodingmachine/gotenberg-php-client )
83+ [ ![ Scrutinizer] ( https://scrutinizer-ci.com/g/thecodingmachine/gotenberg-php-client/badges/quality-score.png?b=master )] ( https://scrutinizer-ci.com/g/thecodingmachine/gotenberg-php-client/?branch=master )
84+ [ ![ Codecov] ( https://codecov.io/gh/thecodingmachine/gotenberg-php-client/branch/master/graph/badge.svg )] ( https://codecov.io/gh/thecodingmachine/gotenberg-php-client/branch/master )
0 commit comments