From a15cf336910bb0b07c9df03bd40108d8344c07cf Mon Sep 17 00:00:00 2001
From: Julien Neuhart
For instance:
<!doctype html> -<html lang="en"> - <head> - <meta charset="utf-8"> - <title>My PDF</title> - </head> - <body> - <h1>Hello world!</h1> - </body> -</html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <title>My PDF</title> + </head> + <body> + <h1>Hello world!</h1> + </body> +</html>
import "github.com/thecodingmachine/gotenberg/pkg" -func main() { +func main() { c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewHTMLRequest("index.html") + req, _ := gotenberg.NewHTMLRequest("index.html") dest := "result.pdf" - c.Store(req, dest) + c.Store(req, dest) }@@ -197,16 +201,16 @@ which will be converted to PDF. 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); -+
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.html and footer.html
Each of them has to be a complete HTML document:
-<html> - <head> - <style> +PHP -<html> + <head> + <style> body { font-size: 8rem; margin: 4rem auto; } - </style> - </head> - <body> - <p> - <span class="pageNumber"></span> of <span class="totalPages"></span> - </p> - </body> -</html> + </style> + </head> + <body> + <p> + <span class="pageNumber"></span> of <span class="totalPages"></span> + </p> + </body> +</html>The following classes allow you to inject printing values:
@@ -267,13 +271,13 @@ Also,footer.htmlCSS properties override the ones fromheadeimport "github.com/thecodingmachine/gotenberg/pkg" -func main() { +func main() { c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewHTMLRequest("index.html") - req.SetHeader("header.html") - req.SetFooter("footer.html") + req, _ := gotenberg.NewHTMLRequest("index.html") + req.SetHeader("header.html") + req.SetFooter("footer.html") dest := "result.pdf" - c.Store(req, dest) + c.Store(req, dest) }@@ -281,20 +285,20 @@ Also,footer.htmlCSS properties override the ones fromheade
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); -+
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);
+
index.html file.
In others words, this will work:
<!doctype html> -<html lang="en"> - <head> - <meta charset="utf-8"> - <title>My PDF</title> - </head> - <body> - <h1>Hello world!</h1> - <img src="img.png"> - </body> -</html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <title>My PDF</title> + </head> + <body> + <h1>Hello world!</h1> + <img src="img.png"> + </body> +</html>
But this won’t:
<!doctype html> -<html lang="en"> - <head> - <meta charset="utf-8"> - <title>My PDF</title> - </head> - <body> - <h1>Hello world!</h1> - <img src="/foo/img.png"> - </body> -</html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <title>My PDF</title> + </head> + <body> + <h1>Hello world!</h1> + <img src="/foo/img.png"> + </body> +</html>
You may also use remote paths for Google fonts, images and so on.
@@ -362,16 +366,16 @@ see to the fonts section.import "github.com/thecodingmachine/gotenberg/pkg" -func main() { +func main() { c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewHTMLRequest("index.html") - req.SetAssets([]string{ + req, _ := gotenberg.NewHTMLRequest("index.html") + req.SetAssets([]string{ "font.woff", "img.gif", "style.css", }) dest := "result.pdf" - c.Store(req, dest) + c.Store(req, dest) }@@ -379,22 +383,22 @@ see to the fonts section. 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); -+
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.
import "github.com/thecodingmachine/gotenberg/pkg" -func main() { +func main() { c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewHTMLRequest("index.html") - req.SetPaperSize(gotenberg.A4) - req.SetMargins(gotenberg.NoMargins) - req.SetLandscape(true) + req, _ := gotenberg.NewHTMLRequest("index.html") + req.SetPaperSize(gotenberg.A4) + req.SetMargins(gotenberg.NoMargins) + req.SetLandscape(true) dest := "result.pdf" - c.Store(req, dest) + c.Store(req, dest) }@@ -448,20 +452,20 @@ Also, you have to set both
paperWidth and paperHeight.
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); -+
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);
+
@@ -485,15 +489,15 @@ in the file index.html. This function will convert a given markdown
For instance:
<!doctype html> -<html lang="en"> - <head> - <meta charset="utf-8"> - <title>My PDF</title> - </head> - <body> +<html lang="en"> + <head> + <meta charset="utf-8"> + <title>My PDF</title> + </head> + <body> {{ toHTML .DirPath "file.md" }} - </body> -</html> + </body> +</html>
index.html. This function will convert a given markdown
import "github.com/thecodingmachine/gotenberg/pkg" -func main() { +func main() { c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewMarkdownRequest("index.html", []string{"file.md"}) + req, _ := gotenberg.NewMarkdownRequest("index.html", []string{"file.md"}) dest := "result.pdf" - c.Store(req, dest) + c.Store(req, dest) }@@ -526,19 +530,19 @@ in the file
index.html. This function will convert a given markdown
PHPuse 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); -+
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);
+
@@ -596,11 +600,11 @@ See the scalability section to find how to mitigate t
import "github.com/thecodingmachine/gotenberg/pkg" -func main() { +func main() { c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewOfficeRequest([]string{"document.docx", "document2.docx"}) + req, _ := gotenberg.NewOfficeRequest([]string{"document.docx", "document2.docx"}) dest := "result.pdf" - c.Store(req, dest) + c.Store(req, dest) }@@ -608,19 +612,19 @@ See the scalability section to find how to mitigate t 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); -+
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);
+
paperWidth and paperHeight.
import "github.com/thecodingmachine/gotenberg/pkg" -func main() { +func main() { c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewOfficeRequest([]string{"document.docx"}) - req.SetPaperSize(gotenberg.A4) - req.SetLandscape(true) + req, _ := gotenberg.NewOfficeRequest([]string{"document.docx"}) + req.SetPaperSize(gotenberg.A4) + req.SetLandscape(true) dest := "result.pdf" - c.Store(req, dest) + c.Store(req, dest) }@@ -669,20 +673,20 @@ Also, you have to set both
paperWidth and paperHeight.
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'), -]; -$request = new OfficeRequest($files); -$request->setPaperSize(Request::A4); -$request->setLandscape(true); -$dirPath = "/foo"; -$filename = $client->store($request, $dirPath); -+
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'),
+];
+$request = new OfficeRequest($files);
+$request->setPaperSize(Request::A4);
+$request->setLandscape(true);
+$dirPath = "/foo";
+$filename = $client->store($request, $dirPath);
+
import "github.com/thecodingmachine/gotenberg/pkg" -func main() { +func main() { c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewMergeRequest([]string{"file.pdf", "file2.pdf"}) + req, _ := gotenberg.NewMergeRequest([]string{"file.pdf", "file2.pdf"}) dest := "result.pdf" - c.Store(req, dest) + c.Store(req, dest) }@@ -744,19 +748,19 @@ will merge them and return the resulting PDF 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); -+
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);
+
@@ -792,12 +796,12 @@ to given URL.
import "github.com/thecodingmachine/gotenberg/pkg" -func main() { +func main() { c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewHTMLRequest("index.html") - req.SetWebhookURL("http://myapp.com/webhook/") + req, _ := gotenberg.NewHTMLRequest("index.html") + req.SetWebhookURL("http://myapp.com/webhook/") dest := "result.pdf" - resp, _ := c.Post(req) + resp, _ := c.Post(req) }@@ -805,16 +809,16 @@ to given URL. 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); -+
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);
+
@@ -859,6 +863,74 @@ redirect a request to a Gotenberg container according to the round-robin strateg
+ ARG GOLANG_VERSION
+ +FROM golang:${GOLANG_VERSION}-stretch
+ +RUN go get github.com/apex/static/cmd/static-docs
+ +WORKDIR /docs
+ +CMD [ “static-docs”, “–in”, “build/docs”, “–out”, “docs”, “–theme”, “gotenberg”, “–title”, “Gotenberg”, “–subtitle”, “A Docker-powered stateless API for converting HTML, Markdown and Office documents to PDF.” ]
+ +