diff --git a/README.md b/README.md index 50e7c71d..c8c7f832 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ At TheCodingMachine, we build a lot of web applications (intranets, extranets an * Performance :zap:: Google Chrome and Libreoffice (unoconv) started once in the background thanks to PM2 * Failure prevention :broken_heart:: PM2 automatically restarts previous processes if they fail * Assets :package:: send your header, footer, images, fonts, stylesheets and so on for converting your HTML and Markdown to beaufitul PDFs! -* Easily interact with the API using our [Go](/pkg) and [PHP](https://github.com/thecodingmachine/gotenberg-php-client) (**WIP**) libraries +* Easily interact with the API using our [Go](/pkg) and [PHP](https://github.com/thecodingmachine/gotenberg-php-client) libraries ## Quick start diff --git a/build/docs/02-html.md b/build/docs/02-html.md index 9d32ac3d..53a6833c 100644 --- a/build/docs/02-html.md +++ b/build/docs/02-html.md @@ -53,7 +53,17 @@ func main() { ### PHP -TODO +```php +use TheCodingMachine\Gotenberg\Client; +use TheCodingMachine\Gotenberg\DocumentFactory; +use TheCodingMachine\Gotenberg\HTMLRequest; + +$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); +$index = DocumentFactory::makeFromPath('index.html', 'index.html'); +$request = new HTMLRequest($index); +$dirPath = "/foo"; +$filename = $client->store($request, $dirPath); +``` ## Header and footer @@ -123,7 +133,21 @@ func main() { ### PHP -TODO +```php +use TheCodingMachine\Gotenberg\Client; +use TheCodingMachine\Gotenberg\DocumentFactory; +use TheCodingMachine\Gotenberg\HTMLRequest; + +$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); +$index = DocumentFactory::makeFromPath('index.html', 'index.html'); +$header = DocumentFactory::makeFromPath('header.html', 'header.html'); +$footer = DocumentFactory::makeFromPath('footer.html', 'footer.html'); +$request = new HTMLRequest($index); +$request->setHeader($header); +$request->setFooter($footer); +$dirPath = "/foo"; +$filename = $client->store($request, $dirPath); +``` ## Assets @@ -204,7 +228,23 @@ func main() { ### PHP -TODO +```php +use TheCodingMachine\Gotenberg\Client; +use TheCodingMachine\Gotenberg\DocumentFactory; +use TheCodingMachine\Gotenberg\HTMLRequest; + +$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); +$index = DocumentFactory::makeFromPath('index.html', 'index.html'); +$assets = [ + DocumentFactory::makeFromPath('style.css', 'style.css'), + DocumentFactory::makeFromPath('img.png', 'img.png'), + DocumentFactory::makeFromPath('font.woff', 'font.woff'), +]; +$request = new HTMLRequest($index); +$request->setAssets($assets); +$dirPath = "/foo"; +$filename = $client->store($request, $dirPath); +``` ## Paper size, margins, orientation @@ -254,4 +294,18 @@ func main() { ### PHP -TODO \ No newline at end of file +```php +use TheCodingMachine\Gotenberg\Client; +use TheCodingMachine\Gotenberg\DocumentFactory; +use TheCodingMachine\Gotenberg\HTMLRequest; +use TheCodingMachine\Gotenberg\Request; + +$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); +$index = DocumentFactory::makeFromPath('index.html', 'index.html'); +$request = new HTMLRequest($index); +$request->setPaperSize(Request::A4); +$request->setMargins(Request::NO_MARGINS); +$request->setLandscape(true); +$dirPath = "/foo"; +$filename = $client->store($request, $dirPath); +``` \ No newline at end of file diff --git a/build/docs/03-markdown.md b/build/docs/03-markdown.md index 43d5277b..e5aa794c 100644 --- a/build/docs/03-markdown.md +++ b/build/docs/03-markdown.md @@ -59,4 +59,17 @@ func main() { ### PHP -TODO +```php +use TheCodingMachine\Gotenberg\Client; +use TheCodingMachine\Gotenberg\DocumentFactory; +use TheCodingMachine\Gotenberg\MarkdownRequest; + +$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); +$index = DocumentFactory::makeFromPath('index.html', 'index.html'); +$markdowns = [ + DocumentFactory::makeFromPath('file.md', 'file.md'), +]; +$request = new MarkdownRequest($index, $markdowns); +$dirPath = "/foo"; +$filename = $client->store($request, $dirPath); +``` diff --git a/build/docs/04-office.md b/build/docs/04-office.md index f783db82..95e9522f 100644 --- a/build/docs/04-office.md +++ b/build/docs/04-office.md @@ -57,7 +57,20 @@ func main() { ### PHP -TODO +```php +use TheCodingMachine\Gotenberg\Client; +use TheCodingMachine\Gotenberg\DocumentFactory; +use TheCodingMachine\Gotenberg\OfficeRequest; + +$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); +$files = [ + DocumentFactory::makeFromPath('document.docx', 'document.docx'), + DocumentFactory::makeFromPath('document2.docx', 'document2.docx'), +]; +$request = new OfficeRequest($files); +$dirPath = "/foo"; +$filename = $client->store($request, $dirPath); +``` ## Fonts diff --git a/build/docs/05-merge.md b/build/docs/05-merge.md index 477cb041..35d48c3e 100644 --- a/build/docs/05-merge.md +++ b/build/docs/05-merge.md @@ -42,4 +42,17 @@ func main() { ### PHP -TODO \ No newline at end of file +```php +use TheCodingMachine\Gotenberg\Client; +use TheCodingMachine\Gotenberg\DocumentFactory; +use TheCodingMachine\Gotenberg\MergeRequest; + +$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); +$files = [ + DocumentFactory::makeFromPath('file.pdf', 'file.pdf'), + DocumentFactory::makeFromPath('file2.pdf', 'file2.pdf'), +]; +$request = new MergeRequest($files); +$dirPath = "/foo"; +$filename = $client->store($request, $dirPath); +``` \ No newline at end of file diff --git a/build/docs/06-webhook.md b/build/docs/06-webhook.md index b63427f6..3a634787 100644 --- a/build/docs/06-webhook.md +++ b/build/docs/06-webhook.md @@ -42,4 +42,14 @@ func main() { ### PHP -TODO \ No newline at end of file +```php +use TheCodingMachine\Gotenberg\Client; +use TheCodingMachine\Gotenberg\DocumentFactory; +use TheCodingMachine\Gotenberg\HTMLRequest; + +$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); +$index = DocumentFactory::makeFromPath('index.html', 'index.html'); +$request = new HTMLRequest($index); +$request->setWebhookURL('http://myapp.com/webhook/'); +$resp = $client->post($request); +``` \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index c966950e..4586bbde 100755 --- a/docs/index.html +++ b/docs/index.html @@ -199,7 +199,16 @@ which will be converted to PDF.
PHP -TODO
+use TheCodingMachine\Gotenberg\Client; +use TheCodingMachine\Gotenberg\DocumentFactory; +use TheCodingMachine\Gotenberg\HTMLRequest; + +$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); +$index = DocumentFactory::makeFromPath('index.html', 'index.html'); +$request = new HTMLRequest($index); +$dirPath = "/foo"; +$filename = $client->store($request, $dirPath); +
footer.html CSS properties override the ones from heade
PHP
-TODO
+use TheCodingMachine\Gotenberg\Client; +use TheCodingMachine\Gotenberg\DocumentFactory; +use TheCodingMachine\Gotenberg\HTMLRequest; + +$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); +$index = DocumentFactory::makeFromPath('index.html', 'index.html'); +$header = DocumentFactory::makeFromPath('header.html', 'header.html'); +$footer = DocumentFactory::makeFromPath('footer.html', 'footer.html'); +$request = new HTMLRequest($index); +$request->setHeader($header); +$request->setFooter($footer); +$dirPath = "/foo"; +$filename = $client->store($request, $dirPath); +
TODO
+use TheCodingMachine\Gotenberg\Client; +use TheCodingMachine\Gotenberg\DocumentFactory; +use TheCodingMachine\Gotenberg\HTMLRequest; + +$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); +$index = DocumentFactory::makeFromPath('index.html', 'index.html'); +$assets = [ + DocumentFactory::makeFromPath('style.css', 'style.css'), + DocumentFactory::makeFromPath('img.png', 'img.png'), + DocumentFactory::makeFromPath('font.woff', 'font.woff'), +]; +$request = new HTMLRequest($index); +$request->setAssets($assets); +$dirPath = "/foo"; +$filename = $client->store($request, $dirPath); +
paperWidth and paperHeight.
PHP
-TODO
+use TheCodingMachine\Gotenberg\Client; +use TheCodingMachine\Gotenberg\DocumentFactory; +use TheCodingMachine\Gotenberg\HTMLRequest; +use TheCodingMachine\Gotenberg\Request; + +$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); +$index = DocumentFactory::makeFromPath('index.html', 'index.html'); +$request = new HTMLRequest($index); +$request->setPaperSize(Request::A4); +$request->setMargins(Request::NO_MARGINS); +$request->setLandscape(true); +$dirPath = "/foo"; +$filename = $client->store($request, $dirPath); +@@ -493,7 +543,19 @@ in the file
index.html which will convert a given markdown file to
PHP
-TODO
+use TheCodingMachine\Gotenberg\Client; +use TheCodingMachine\Gotenberg\DocumentFactory; +use TheCodingMachine\Gotenberg\MarkdownRequest; + +$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); +$index = DocumentFactory::makeFromPath('index.html', 'index.html'); +$markdowns = [ + DocumentFactory::makeFromPath('file.md', 'file.md'), +]; +$request = new MarkdownRequest($index, $markdowns); +$dirPath = "/foo"; +$filename = $client->store($request, $dirPath); +@@ -566,7 +628,19 @@ See the scalability section to find how to mitigate t PHP -
TODO
+use TheCodingMachine\Gotenberg\Client; +use TheCodingMachine\Gotenberg\DocumentFactory; +use TheCodingMachine\Gotenberg\OfficeRequest; + +$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); +$files = [ + DocumentFactory::makeFromPath('document.docx', 'document.docx'), + DocumentFactory::makeFromPath('document2.docx', 'document2.docx'), +]; +$request = new OfficeRequest($files); +$dirPath = "/foo"; +$filename = $client->store($request, $dirPath); +
TODO
+use TheCodingMachine\Gotenberg\Client; +use TheCodingMachine\Gotenberg\DocumentFactory; +use TheCodingMachine\Gotenberg\MergeRequest; + +$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); +$files = [ + DocumentFactory::makeFromPath('file.pdf', 'file.pdf'), + DocumentFactory::makeFromPath('file2.pdf', 'file2.pdf'), +]; +$request = new MergeRequest($files); +$dirPath = "/foo"; +$filename = $client->store($request, $dirPath); +@@ -687,7 +773,16 @@ to given URL. PHP -
TODO
+use TheCodingMachine\Gotenberg\Client; +use TheCodingMachine\Gotenberg\DocumentFactory; +use TheCodingMachine\Gotenberg\HTMLRequest; + +$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); +$index = DocumentFactory::makeFromPath('index.html', 'index.html'); +$request = new HTMLRequest($index); +$request->setWebhookURL('http://myapp.com/webhook/'); +$resp = $client->post($request); +