diff --git a/Makefile b/Makefile index ece45530..5a0d93fb 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,10 @@ GOLANG_VERSION=1.13 VERSION=snapshot DOCKER_USER= DOCKER_PASSWORD= -DOCKER_REPOSITORY=thecodingmachine -GOLANGCI_LINT_VERSION=1.19.1 +DOCKER_REGISTRY=thecodingmachine +GOTENBERG_USER_GID=1001 +GOTENBERG_USER_UID=1001 +GOLANGCI_LINT_VERSION=1.20.1 CODE_COVERAGE=0 TINI_VERSION=0.18.0 MAXIMUM_WAIT_TIMEOUT=30.0 @@ -15,16 +17,17 @@ DEFAULT_LISTEN_PORT=3000 DISABLE_GOOGLE_CHROME=0 DISABLE_UNOCONV=0 LOG_LEVEL=INFO +ROOT_PATH=/ DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE=1048576 # build the base Docker image. base: - docker build -t $(DOCKER_REPOSITORY)/gotenberg:base -f build/base/Dockerfile . + docker build --build-arg GOTENBERG_USER_GID=$(GOTENBERG_USER_GID) --build-arg GOTENBERG_USER_UID=$(GOTENBERG_USER_UID) -t $(DOCKER_REGISTRY)/gotenberg:base -f build/base/Dockerfile . # build the workspace Docker image. workspace: make base - docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) -t $(DOCKER_REPOSITORY)/gotenberg:workspace -f build/workspace/Dockerfile . + docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) -t $(DOCKER_REGISTRY)/gotenberg:workspace -f build/workspace/Dockerfile . # gofmt and goimports all go files. fmt: @@ -34,30 +37,30 @@ fmt: # run all linters. lint: make workspace - docker build --build-arg GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION) -t $(DOCKER_REPOSITORY)/gotenberg:lint -f build/lint/Dockerfile . - docker run --rm $(DOCKER_REPOSITORY)/gotenberg:lint + docker build --build-arg GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION) -t $(DOCKER_REGISTRY)/gotenberg:lint -f build/lint/Dockerfile . + docker run --rm $(DOCKER_REGISTRY)/gotenberg:lint # run all tests. tests: make workspace - ./scripts/tests.sh $(DOCKER_REPOSITORY) $(CODE_COVERAGE) + ./scripts/tests.sh $(DOCKER_REGISTRY) $(CODE_COVERAGE) # generate documentation. doc: make workspace - docker build -t $(DOCKER_REPOSITORY)/gotenberg:docs -f build/docs/Dockerfile . - docker run --rm -it -v "$(PWD):/gotenberg/docs" $(DOCKER_REPOSITORY)/gotenberg:docs + docker build -t $(DOCKER_REGISTRY)/gotenberg:docs -f build/docs/Dockerfile . + docker run --rm -it -v "$(PWD):/gotenberg/docs" $(DOCKER_REGISTRY)/gotenberg:docs # build Gotenberg Docker image. image: make workspace - docker build --build-arg VERSION=$(VERSION) --build-arg TINI_VERSION=$(TINI_VERSION) -t $(DOCKER_REPOSITORY)/gotenberg:$(VERSION) -f build/package/Dockerfile . + docker build --build-arg VERSION=$(VERSION) --build-arg TINI_VERSION=$(TINI_VERSION) -t $(DOCKER_REGISTRY)/gotenberg:$(VERSION) -f build/package/Dockerfile . # start the API using previously built Docker image. gotenberg: - docker run -it --rm -e MAXIMUM_WAIT_TIMEOUT=$(MAXIMUM_WAIT_TIMEOUT) -e MAXIMUM_WAIT_DELAY=$(MAXIMUM_WAIT_DELAY) -e MAXIMUM_WEBHOOK_URL_TIMEOUT=$(MAXIMUM_WEBHOOK_URL_TIMEOUT) -e DEFAULT_WEBHOOK_URL_TIMEOUT=$(DEFAULT_WEBHOOK_URL_TIMEOUT) -e MAXIMUM_WEBHOOK_URL_TIMEOUT=$(MAXIMUM_WEBHOOK_URL_TIMEOUT) -e DEFAULT_LISTEN_PORT=$(DEFAULT_LISTEN_PORT) -e DISABLE_GOOGLE_CHROME=$(DISABLE_GOOGLE_CHROME) -e DISABLE_UNOCONV=$(DISABLE_UNOCONV) -e LOG_LEVEL=$(LOG_LEVEL) -e DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE=$(DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE) -p "$(DEFAULT_LISTEN_PORT):$(DEFAULT_LISTEN_PORT)" $(DOCKER_REPOSITORY)/gotenberg:$(VERSION) + docker run -it --rm -e MAXIMUM_WAIT_TIMEOUT=$(MAXIMUM_WAIT_TIMEOUT) -e MAXIMUM_WAIT_DELAY=$(MAXIMUM_WAIT_DELAY) -e MAXIMUM_WEBHOOK_URL_TIMEOUT=$(MAXIMUM_WEBHOOK_URL_TIMEOUT) -e DEFAULT_WEBHOOK_URL_TIMEOUT=$(DEFAULT_WEBHOOK_URL_TIMEOUT) -e MAXIMUM_WEBHOOK_URL_TIMEOUT=$(MAXIMUM_WEBHOOK_URL_TIMEOUT) -e DEFAULT_LISTEN_PORT=$(DEFAULT_LISTEN_PORT) -e DISABLE_GOOGLE_CHROME=$(DISABLE_GOOGLE_CHROME) -e DISABLE_UNOCONV=$(DISABLE_UNOCONV) -e LOG_LEVEL=$(LOG_LEVEL) -e ROOT_PATH=$(ROOT_PATH) -e DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE=$(DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE) -p "$(DEFAULT_LISTEN_PORT):$(DEFAULT_LISTEN_PORT)" $(DOCKER_REPOSITORY)/gotenberg:$(VERSION) # publish Gotenberg images according to version. publish: make workspace - ./scripts/publish.sh $(GOLANG_VERSION) $(TINI_VERSION) $(DOCKER_REPOSITORY) $(VERSION) $(DOCKER_USER) $(DOCKER_PASSWORD) \ No newline at end of file + ./scripts/publish.sh $(GOLANG_VERSION) $(TINI_VERSION) $(DOCKER_REGISTRY) $(VERSION) $(DOCKER_USER) $(DOCKER_PASSWORD) \ No newline at end of file diff --git a/build/base/Dockerfile b/build/base/Dockerfile index c40df230..31f78d84 100644 --- a/build/base/Dockerfile +++ b/build/base/Dockerfile @@ -104,7 +104,10 @@ COPY build/base/fonts.conf /etc/fonts/conf.d/100-gotenberg.conf # | non-root user. # | -RUN groupadd --gid 1001 gotenberg \ - && useradd --uid 1001 --gid gotenberg --shell /bin/bash --home /gotenberg --no-create-home gotenberg \ +ARG GOTENBERG_USER_GID=1001 +ARG GOTENBERG_USER_UID=1001 + +RUN groupadd --gid ${GOTENBERG_USER_GID} gotenberg \ + && useradd --uid ${GOTENBERG_USER_UID} --gid gotenberg --shell /bin/bash --home /gotenberg --no-create-home gotenberg \ && mkdir /gotenberg \ && chown gotenberg: /gotenberg \ No newline at end of file diff --git a/build/docs/content/01-install.md b/build/docs/content/01-install.md index ec4cdca5..7e2c4d0e 100644 --- a/build/docs/content/01-install.md +++ b/build/docs/content/01-install.md @@ -4,8 +4,6 @@ title: Install Gotenberg is shipped within a Docker image. -> It uses a dedicated non-root user called `gotenberg` with uid and gid `1001`. - You may start it with: ```bash @@ -14,6 +12,23 @@ $ docker run --rm -p 3000:3000 thecodingmachine/gotenberg:6 > The API will be available at [http://localhost:3000](http://localhost:3000). +The image uses a dedicated non-root user called `gotenberg` with uid and gid `1001`. + +If you wish to change those uid and gid, you will have to: + +* clone the project +* re-build the image +* publish the image in your own Docker registry + +For instance: + +```bash +$ git clone https://github.com/thecodingmachine/gotenberg.git +$ make publish GOTENBERG_USER_GID=your_custom_gid GOTENBERG_USER_UID=your_custom_uid DOCKER_REGISTRY=your_registry DOCKER_USER=registry_user DOCKER_PASSWORD=registry_password VERSION=6.1.0 +``` + +> `master` branch is always up-to-date with the latest version of the API. + ## Docker Compose You may also add it in your Docker Compose stack: @@ -39,7 +54,7 @@ Make sure to provide enough memory and CPU requests (for instance `512Mi` and `0 > The more resources are granted, the quicker will be the conversions. -In the deployment specification of the pod, also specify the uid `1001` of the user `gotenberg`: +In the deployment specification of the pod, also specify the uid of the user `gotenberg`: ``` securityContext: diff --git a/build/docs/content/02-clients.md b/build/docs/content/02-clients.md index 560601e6..0f4ce7d2 100644 --- a/build/docs/content/02-clients.md +++ b/build/docs/content/02-clients.md @@ -7,9 +7,11 @@ We provide clients in various languages for easing the interactions with the API ## Go client ```bash -$ go get -u github.com/thecodingmachine/gotenberg-go-client/v6 +$ go get -u github.com/thecodingmachine/gotenberg-go-client/v7 ``` +See also the example from the [README](https://github.com/thecodingmachine/gotenberg-go-client/blob/master/README.md). + ## PHP client Unless your project already has a PSR7 `HttpClient`, install `php-http/guzzle6-adapter`: @@ -18,12 +20,14 @@ Unless your project already has a PSR7 `HttpClient`, install `php-http/guzzle6-a $ composer require php-http/guzzle6-adapter ``` -Then the PHP client: +Then the [PHP client](https://github.com/thecodingmachine/gotenberg-php-client): ```bash $ composer require thecodingmachine/gotenberg-php-client ``` +See also the example from the [README](https://github.com/thecodingmachine/gotenberg-php-client/blob/master/README.md). + ## Community clients * [JavaScript/TypeScript client](https://github.com/yumauri/gotenberg-js-client) by [yumauri](https://github.com/yumauri) diff --git a/build/docs/content/03-environment-variables.md b/build/docs/content/03-environment-variables.md index e1f18731..b1522740 100644 --- a/build/docs/content/03-environment-variables.md +++ b/build/docs/content/03-environment-variables.md @@ -23,6 +23,18 @@ You may customize this value with the environment variable `DEFAULT_LISTEN_PORT` This environment variable accepts any string that can be turned into a port number. +## Root path + +By default, the API root path is `/`. + +You may customize this value with the environment variable `ROOT_PATH`. + +This environment variable accepts a string starting and ending with `/`. + +For instance, `/gotenberg/` is a valid value while `gotenberg` is not. + +> This is useful if you wish to do service discovery via URL paths. + ## Disable Google Chrome In order to save some resources, the Gotenberg image accepts the environment variable `DISABLE_GOOGLE_CHROME` diff --git a/build/docs/content/04-html.md b/build/docs/content/04-html.md index 060da6ef..85c426d5 100644 --- a/build/docs/content/04-html.md +++ b/build/docs/content/04-html.md @@ -39,14 +39,13 @@ $ curl --request POST \ ### Go ```golang -import "github.com/thecodingmachine/gotenberg-go-client/v6" +import "github.com/thecodingmachine/gotenberg-go-client/v7" -func main() { - c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewHTMLRequest("index.html") - dest := "result.pdf" - c.Store(req, dest) -} +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file") +req := gotenberg.NewHTMLRequest(index) +dest := "result.pdf" +c.Store(req, dest) ``` ### PHP @@ -57,9 +56,9 @@ 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'); +$index = DocumentFactory::makeFromPath('index.html', '/path/to/file'); $request = new HTMLRequest($index); -$dest = "result.pdf"; +$dest = 'result.pdf'; $client->store($request, $dest); ``` @@ -120,16 +119,17 @@ $ curl --request POST \ ### Go ```golang -import "github.com/thecodingmachine/gotenberg-go-client/v6" +import "github.com/thecodingmachine/gotenberg-go-client/v7" -func main() { - c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewHTMLRequest("index.html") - req.Header("header.html") - req.Footer("footer.html") - dest := "result.pdf" - c.Store(req, dest) -} +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file") +header, _ := gotenberg.NewDocumentFromPath("header.html", "/path/to/file") +footer, _ := gotenberg.NewDocumentFromPath("footer.html", "/path/to/file") +req := gotenberg.NewHTMLRequest(index) +req.Header(header) +req.Footer(footer) +dest := "result.pdf" +c.Store(req, dest) ``` ### PHP @@ -140,13 +140,13 @@ 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'); +$index = DocumentFactory::makeFromPath('index.html', '/path/to/file'); +$header = DocumentFactory::makeFromPath('header.html', '/path/to/file'); +$footer = DocumentFactory::makeFromPath('footer.html', '/path/to/file'); $request = new HTMLRequest($index); $request->setHeader($header); $request->setFooter($footer); -$dest = "result.pdf"; +$dest = 'result.pdf'; $client->store($request, $dest); ``` @@ -210,15 +210,17 @@ $ curl --request POST \ ### Go ```golang -import "github.com/thecodingmachine/gotenberg-go-client/v6" +import "github.com/thecodingmachine/gotenberg-go-client/v7" -func main() { - c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewHTMLRequest("index.html") - req.Assets("font.woff", "img.gif", "style.css") - dest := "result.pdf" - c.Store(req, dest) -} +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file") +style, _ := gotenberg.NewDocumentFromPath("style.css", "/path/to/file") +img, _ := gotenberg.NewDocumentFromPath("img.png", "/path/to/file") +font, _ := gotenberg.NewDocumentFromPath("font.woff", "/path/to/file") +req := gotenberg.NewHTMLRequest(index) +req.Assets(style, img, font) +dest := "result.pdf" +c.Store(req, dest) ``` ### PHP @@ -229,15 +231,15 @@ 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'); +$index = DocumentFactory::makeFromPath('index.html', '/path/to/file'); $assets = [ - DocumentFactory::makeFromPath('style.css', 'style.css'), - DocumentFactory::makeFromPath('img.png', 'img.png'), - DocumentFactory::makeFromPath('font.woff', 'font.woff'), + DocumentFactory::makeFromPath('style.css', '/path/to/file'), + DocumentFactory::makeFromPath('img.png', '/path/to/file'), + DocumentFactory::makeFromPath('font.woff', '/path/to/file'), ]; $request = new HTMLRequest($index); $request->setAssets($assets); -$dest = "result.pdf"; +$dest = 'result.pdf'; $client->store($request, $dest); ``` @@ -269,17 +271,16 @@ $ curl --request POST \ ### Go ```golang -import "github.com/thecodingmachine/gotenberg-go-client/v6" +import "github.com/thecodingmachine/gotenberg-go-client/v7" -func main() { - c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewHTMLRequest("index.html") - req.PaperSize(gotenberg.A4) - req.Margins(gotenberg.NoMargins) - req.Landscape(true) - dest := "result.pdf" - c.Store(req, dest) -} +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file") +req := gotenberg.NewHTMLRequest(index) +req.PaperSize(gotenberg.A4) +req.Margins(gotenberg.NoMargins) +req.Landscape(true) +dest := "result.pdf" +c.Store(req, dest) ``` ### PHP @@ -291,12 +292,59 @@ 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'); +$index = DocumentFactory::makeFromPath('index.html', '/path/to/file'); $request = new HTMLRequest($index); $request->setPaperSize(Request::A4); $request->setMargins(Request::NO_MARGINS); $request->setLandscape(true); -$dest = "result.pdf"; +$dest = 'result.pdf'; +$client->store($request, $dest); +``` + +## Page ranges + +You may specify the page ranges to convert. + +The format is the same as the one from the print options +of Google Chrome, e.g. `1-5,8,11-13`. + +### cURL + +```bash +$ curl --request POST \ + --url http://localhost:3000/convert/html \ + --header 'Content-Type: multipart/form-data' \ + --form files=@index.html \ + --form pageRanges='1-3,5' \ + -o result.pdf +``` + +### Go + +```golang +import "github.com/thecodingmachine/gotenberg-go-client/v7" + +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file") +req := gotenberg.NewHTMLRequest(index) +req.PageRanges("1-3,5") +dest := "result.pdf" +c.Store(req, dest) +``` + +### PHP + +```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', '/path/to/file'); +$request = new HTMLRequest($index); +$request->setPageRanges('1-3,5'); +$dest = 'result.pdf'; $client->store($request, $dest); ``` @@ -322,15 +370,14 @@ $ curl --request POST \ ### Go ```golang -import "github.com/thecodingmachine/gotenberg-go-client/v6" +import "github.com/thecodingmachine/gotenberg-go-client/v7" -func main() { - c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewHTMLRequest("index.html") - req.WaitDelay(5.5) - dest := "result.pdf" - c.Store(req, dest) -} +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file") +req := gotenberg.NewHTMLRequest(index) +req.WaitDelay(5.5) +dest := "result.pdf" +c.Store(req, dest) ``` ### PHP @@ -342,10 +389,10 @@ 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'); +$index = DocumentFactory::makeFromPath('index.html', '/path/to/file'); $request = new HTMLRequest($index); $request->setWaitDelay(5.5); -$dest = "result.pdf"; +$dest = 'result.pdf'; $client->store($request, $dest); ``` @@ -374,15 +421,14 @@ $ curl --request POST \ ### Go ```golang -import "github.com/thecodingmachine/gotenberg-go-client/v6" +import "github.com/thecodingmachine/gotenberg-go-client/v7" -func main() { - c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewHTMLRequest("index.html") - req.GoogleChromeRpccBufferSize(1048576) - dest := "result.pdf" - c.Store(req, dest) -} +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file") +req := gotenberg.NewHTMLRequest(index) +req.GoogleChromeRpccBufferSize(1048576) +dest := "result.pdf" +c.Store(req, dest) ``` ### PHP @@ -394,9 +440,9 @@ 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'); +$index = DocumentFactory::makeFromPath('index.html', '/path/to/file'); $request = new HTMLRequest($index); $request->setGoogleChromeRpccBufferSize(1048576); -$dest = "result.pdf"; +$dest = 'result.pdf'; $client->store($request, $dest); ``` diff --git a/build/docs/content/05-url.md b/build/docs/content/05-url.md index 6517843a..fc307445 100644 --- a/build/docs/content/05-url.md +++ b/build/docs/content/05-url.md @@ -31,15 +31,13 @@ $ curl --request POST \ ### Go ```golang -import "github.com/thecodingmachine/gotenberg-go-client/v6" +import "github.com/thecodingmachine/gotenberg-go-client/v7" -func main() { - c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req := gotenberg.NewURLRequest("https://google.com") - req.Margins(gotenberg.NoMargins) - dest := "result.pdf" - c.Store(req, dest) -} +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +req := gotenberg.NewURLRequest("https://google.com") +req.Margins(gotenberg.NoMargins) +dest := "result.pdf" +c.Store(req, dest) ``` ### PHP @@ -51,6 +49,55 @@ use TheCodingMachine\Gotenberg\URLRequest; $client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); $request = new URLRequest('https://google.com'); $request->setMargins(Request::NO_MARGINS); -$dest = "result.pdf"; +$dest = 'result.pdf'; +$client->store($request, $dest); +``` + +## Custom HTTP headers + +You may send your own HTTP headers to the `remoteURL`. + +For instance, by adding the HTTP header `Gotenberg-Remoteurl-Your-Header` to your request, +the API will send a request to the `remoteURL` with the HTTP header `Your-Header`. + +> **Attention:** the API uses a canonical format for the HTTP headers: +> it transforms the first +> letter and any letter following a hyphen to upper case; +> the rest are converted to lowercase. For example, the +> canonical key for `accept-encoding` is `Accept-Encoding`. + +### cURL + +```bash +$ curl --request POST \ + --url http://localhost:3000/convert/url \ + --header 'Content-Type: multipart/form-data' \ + --header 'Gotenberg-Remoteurl-Your-Header: Foo' \ + --form remoteURL=https://google.com \ + -o result.pdf +``` + +### Go + +```golang +import "github.com/thecodingmachine/gotenberg-go-client/v7" + +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +req := gotenberg.NewURLRequest("https://google.com") +req.AddRemoteURLHTTPHeader("Your-Header", "Foo") +dest := "result.pdf" +c.Store(req, dest) +``` + +### PHP + +```php +use TheCodingMachine\Gotenberg\Client; +use TheCodingMachine\Gotenberg\URLRequest; + +$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); +$request = new URLRequest('https://google.com'); +$request->addRemoteURLHTTPHeader('Your-Header', 'Foo') +$dest = 'result.pdf'; $client->store($request, $dest); ``` diff --git a/build/docs/content/06-markdown.md b/build/docs/content/06-markdown.md index 66c50ee4..5838ea7b 100644 --- a/build/docs/content/06-markdown.md +++ b/build/docs/content/06-markdown.md @@ -42,14 +42,14 @@ $ curl --request POST \ ### Go ```golang -import "github.com/thecodingmachine/gotenberg-go-client/v6" +import "github.com/thecodingmachine/gotenberg-go-client/v7" -func main() { - c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewMarkdownRequest("index.html", "file.md") - dest := "result.pdf" - c.Store(req, dest) -} +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file") +markdown, _ := gotenberg.NewDocumentFromPath("file.md", "/path/to/file") +req := gotenberg.NewMarkdownRequest(index, markdown) +dest := "result.pdf" +c.Store(req, dest) ``` ### PHP @@ -60,11 +60,11 @@ 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'); +$index = DocumentFactory::makeFromPath('index.html', '/path/to/file'); $markdowns = [ - DocumentFactory::makeFromPath('file.md', 'file.md'), + DocumentFactory::makeFromPath('file.md', '/path/to/file'), ]; $request = new MarkdownRequest($index, $markdowns); -$dest = "result.pdf"; +$dest = 'result.pdf'; $client->store($request, $dest); ``` diff --git a/build/docs/content/07-office.md b/build/docs/content/07-office.md index 39e91e37..1dbae793 100644 --- a/build/docs/content/07-office.md +++ b/build/docs/content/07-office.md @@ -41,14 +41,14 @@ $ curl --request POST \ ### Go ```golang -import "github.com/thecodingmachine/gotenberg-go-client/v6" +import "github.com/thecodingmachine/gotenberg-go-client/v7" -func main() { - c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewOfficeRequest("document.docx", "document2.docx") - dest := "result.pdf" - c.Store(req, dest) -} +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +doc, _ := gotenberg.NewDocumentFromPath("document.docx", "/path/to/file") +doc2, _ := gotenberg.NewDocumentFromPath("document2.docx", "/path/to/file") +req := gotenberg.NewOfficeRequest(doc, doc2) +dest := "result.pdf" +c.Store(req, dest) ``` ### PHP @@ -60,11 +60,11 @@ 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'), + DocumentFactory::makeFromPath('document.docx', '/path/to/file'), + DocumentFactory::makeFromPath('document2.docx', '/path/to/file'), ]; $request = new OfficeRequest($files); -$dest = "result.pdf"; +$dest = 'result.pdf'; $client->store($request, $dest); ``` @@ -88,15 +88,14 @@ $ curl --request POST \ ### Go ```golang -import "github.com/thecodingmachine/gotenberg-go-client/v6" +import "github.com/thecodingmachine/gotenberg-go-client/v7" -func main() { - c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewOfficeRequest("document.docx") - req.Landscape(true) - dest := "result.pdf" - c.Store(req, dest) -} +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +doc, _ := gotenberg.NewDocumentFromPath("document.docx", "/path/to/file") +req := gotenberg.NewOfficeRequest(doc) +req.Landscape(true) +dest := "result.pdf" +c.Store(req, dest) ``` ### PHP @@ -108,10 +107,61 @@ use TheCodingMachine\Gotenberg\OfficeRequest; $client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client()); $files = [ - DocumentFactory::makeFromPath('document.docx', 'document.docx'), + DocumentFactory::makeFromPath('document.docx', '/path/to/file'), ]; $request = new OfficeRequest($files); $request->setLandscape(true); -$dest = "result.pdf"; +$dest = 'result.pdf'; +$client->store($request, $dest); +``` + +## Page ranges + +You may specify the page ranges to convert. + +The format is the same as the one from the print options +of LibreOffice, e.g. `1-1` or `1-4`. + +> **Attention:** if more than one document, the page ranges will be +> applied for each document. + +### cURL + +```bash +$ curl --request POST \ + --url http://localhost:3000/convert/office \ + --header 'Content-Type: multipart/form-data' \ + --form files=@document.docx \ + --form pageRanges='1-3' \ + -o result.pdf +``` + +### Go + +```golang +import "github.com/thecodingmachine/gotenberg-go-client/v7" + +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +doc, _ := gotenberg.NewDocumentFromPath("document.docx", "/path/to/file") +req := gotenberg.NewOfficeRequest(doc) +req.PageRanges("1-3") +dest := "result.pdf" +c.Store(req, dest) +``` + +### PHP + +```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', '/path/to/file'), +]; +$request = new OfficeRequest($files); +$request->setPageRanges('1-3'); +$dest = 'result.pdf'; $client->store($request, $dest); ``` diff --git a/build/docs/content/08-merge.md b/build/docs/content/08-merge.md index 49ac0b2b..8e693743 100644 --- a/build/docs/content/08-merge.md +++ b/build/docs/content/08-merge.md @@ -27,14 +27,14 @@ $ curl --request POST \ ### Go ```golang -import "github.com/thecodingmachine/gotenberg-go-client/v6" +import "github.com/thecodingmachine/gotenberg-go-client/v7" -func main() { - c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewMergeRequest("file.pdf", "file2.pdf") - dest := "result.pdf" - c.Store(req, dest) -} +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +pdf, _ := gotenberg.NewDocumentFromPath("file.pdf", "/path/to/file") +pdf2, _ := gotenberg.NewDocumentFromPath("file2.pdf", "/path/to/file") +req := gotenberg.NewMergeRequest(pdf, pdf2) +dest := "result.pdf" +c.Store(req, dest) ``` ### PHP @@ -46,10 +46,10 @@ 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'), + DocumentFactory::makeFromPath('file.pdf', '/path/to/file'), + DocumentFactory::makeFromPath('file2.pdf', '/path/to/file'), ]; $request = new MergeRequest($files); -$dest = "result.pdf"; +$dest = 'result.pdf'; $client->store($request, $dest); ``` diff --git a/build/docs/content/09-timeout.md b/build/docs/content/09-timeout.md index 9392b84f..c7cbbd70 100644 --- a/build/docs/content/09-timeout.md +++ b/build/docs/content/09-timeout.md @@ -26,14 +26,13 @@ $ curl --request POST \ ### Go ```golang -import "github.com/thecodingmachine/gotenberg-go-client/v6" +import "github.com/thecodingmachine/gotenberg-go-client/v7" -func main() { - c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewHTMLRequest("index.html") - req.WaitTimeout(2.5) - resp, _ := c.Post(req) -} +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file") +req := gotenberg.NewHTMLRequest(index) +req.WaitTimeout(2.5) +resp, _ := c.Post(req) ``` ### PHP @@ -45,9 +44,9 @@ 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'); +$index = DocumentFactory::makeFromPath('index.html', '/path/to/file'); $request = new HTMLRequest($index); $request->setWaitTimeout(2.5); -$dest = "result.pdf"; +$dest = 'result.pdf'; $client->store($request, $dest); ``` diff --git a/build/docs/content/10-webhook.md b/build/docs/content/10-webhook.md index fff2456d..3d5e69e1 100644 --- a/build/docs/content/10-webhook.md +++ b/build/docs/content/10-webhook.md @@ -24,14 +24,13 @@ $ curl --request POST \ ### Go ```golang -import "github.com/thecodingmachine/gotenberg-go-client/v6" +import "github.com/thecodingmachine/gotenberg-go-client/v7" -func main() { - c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewHTMLRequest("index.html") - req.WebhookURL("http://myapp.com/webhook/") - resp, _ := c.Post(req) -} +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file") +req := gotenberg.NewHTMLRequest(index) +req.WebhookURL("http://myapp.com/webhook/") +resp, _ := c.Post(req) ``` ### PHP @@ -42,7 +41,7 @@ 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'); +$index = DocumentFactory::makeFromPath('index.html', '/path/to/file'); $request = new HTMLRequest($index); $request->setWebhookURL('http://myapp.com/webhook/'); $resp = $client->post($request); @@ -58,9 +57,7 @@ It takes a float as value (e.g `2.5` for 2.5 seconds). > You may also define this value globally: see the [environment variables](#environment_variables.default_webhook_url_timeout) section. -### Examples - -#### cURL +### cURL ```bash $ curl --request POST \ @@ -71,21 +68,20 @@ $ curl --request POST \ --form webhookURLTimeout=2.5 ``` -#### Go +### Go ```golang -import "github.com/thecodingmachine/gotenberg-go-client/v6" +import "github.com/thecodingmachine/gotenberg-go-client/v7" -func main() { - c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewHTMLRequest("index.html") - req.WebhookURL("http://myapp.com/webhook/") - req.WebhookURLTimeout(2.5) - resp, _ := c.Post(req) -} +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file") +req := gotenberg.NewHTMLRequest(index) +req.WebhookURL("http://myapp.com/webhook/") +req.WebhookURLTimeout(2.5) +resp, _ := c.Post(req) ``` -#### PHP +### PHP ```php use TheCodingMachine\Gotenberg\Client; @@ -93,9 +89,61 @@ 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'); +$index = DocumentFactory::makeFromPath('index.html', '/path/to/file'); $request = new HTMLRequest($index); $request->setWebhookURL('http://myapp.com/webhook/'); $request->setWebhookURLTimeout(2.5); $resp = $client->post($request); ``` + +## Custom HTTP headers + +You may send your own HTTP headers to the `webhookURL`. + +For instance, by adding the HTTP header `Gotenberg-Webhookurl-Your-Header` to your request, +the API will send a request to the `webhookURL` with the HTTP header `Your-Header`. + +> **Attention:** the API uses a canonical format for the HTTP headers: +> it transforms the first +> letter and any letter following a hyphen to upper case; +> the rest are converted to lowercase. For example, the +> canonical key for `accept-encoding` is `Accept-Encoding`. + +### cURL + +```bash +$ curl --request POST \ + --url http://localhost:3000/convert/html \ + --header 'Content-Type: multipart/form-data' \ + --header 'Gotenberg-Webhookurl-Your-Header: Foo' \ + --form files=@index.html \ + --form webhookURL='http://myapp.com/webhook/' +``` + +### Go + +```golang +import "github.com/thecodingmachine/gotenberg-go-client/v7" + +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file") +req := gotenberg.NewHTMLRequest(index) +req.WebhookURL("http://myapp.com/webhook/") +req.AddWebhookURLHTTPHeader("Your-Header", "Foo") +resp, _ := c.Post(req) +``` + +### PHP + +```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', '/path/to/file'); +$request = new HTMLRequest($index); +$request->setWebhookURL('http://myapp.com/webhook/'); +$request->addWebhookURLHTTPHeader('Your-Header', 'Foo'); +$resp = $client->post($request); +``` \ No newline at end of file diff --git a/build/docs/content/11-result-filename.md b/build/docs/content/11-result-filename.md index aabb4177..94bc230f 100644 --- a/build/docs/content/11-result-filename.md +++ b/build/docs/content/11-result-filename.md @@ -24,14 +24,13 @@ $ curl --request POST \ ### Go ```golang -import "github.com/thecodingmachine/gotenberg-go-client/v6" +import "github.com/thecodingmachine/gotenberg-go-client/v7" -func main() { - c := &gotenberg.Client{Hostname: "http://localhost:3000"} - req, _ := gotenberg.NewHTMLRequest("index.html") - req.ResultFilename("foo.pdf") - resp, _ := c.Post(req) -} +c := &gotenberg.Client{Hostname: "http://localhost:3000"} +index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file") +req := gotenberg.NewHTMLRequest(index) +req.ResultFilename("foo.pdf") +resp, _ := c.Post(req) ``` ### PHP @@ -43,7 +42,7 @@ 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'); +$index = DocumentFactory::makeFromPath('index.html', '/path/to/file'); $request = new HTMLRequest($index); $request->setResultFilename('foo.pdf'); $resp = $client->post($request); diff --git a/build/lint/Dockerfile b/build/lint/Dockerfile index fd08c9c5..42a8c054 100644 --- a/build/lint/Dockerfile +++ b/build/lint/Dockerfile @@ -33,4 +33,4 @@ RUN go mod download &&\ # Copy our code source. COPY --chown=gotenberg:gotenberg . . -CMD ["golangci-lint", "run" ,"--tests=false", "--enable-all", "--disable=dupl", "--disable=funlen" ] \ No newline at end of file +CMD ["golangci-lint", "run" ,"--tests=false", "--enable-all", "--disable=dupl", "--disable=funlen", "--disable=wsl", "--disable=gocognit" ] \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 85c3b75a..4853baa6 100755 --- a/docs/index.html +++ b/docs/index.html @@ -132,33 +132,49 @@ Install

Gotenberg is shipped within a Docker image.

-
-

It uses a dedicated non-root user called gotenberg with uid and gid 1001.

-
-

You may start it with:

-
$ docker run --rm -p 3000:3000 thecodingmachine/gotenberg:6
+
$ docker run --rm -p 3000:3000 thecodingmachine/gotenberg:6
 

The API will be available at http://localhost:3000.

+

The image uses a dedicated non-root user called gotenberg with uid and gid 1001.

+ +

If you wish to change those uid and gid, you will have to:

+ + + +

For instance:

+ +
$ git clone https://github.com/thecodingmachine/gotenberg.git
+$ make publish GOTENBERG_USER_GID=your_custom_gid GOTENBERG_USER_UID=your_custom_uid DOCKER_REGISTRY=your_registry DOCKER_USER=registry_user DOCKER_PASSWORD=registry_password VERSION=6.1.0 
+
+ +
+

master branch is always up-to-date with the latest version of the API.

+
+

Docker Compose

You may also add it in your Docker Compose stack:

-
version: '3'
+
version: '3'
 
-services:
+services:
 
   # your others services
 
-  gotenberg:
-    image: thecodingmachine/gotenberg:6
+  gotenberg:
+    image: thecodingmachine/gotenberg:6
 
@@ -177,7 +193,7 @@

The more resources are granted, the quicker will be the conversions.

-

In the deployment specification of the pod, also specify the uid 1001 of the user gotenberg:

+

In the deployment specification of the pod, also specify the uid of the user gotenberg:

securityContext:
   privileged: false
@@ -205,9 +221,11 @@ Gotenberg API is available at http://localhost:3
 	
 Go client
 
-
$ go get -u github.com/thecodingmachine/gotenberg-go-client/v6
+
$ go get -u github.com/thecodingmachine/gotenberg-go-client/v7
 
+

See also the example from the README.

+

PHP client

@@ -217,11 +235,13 @@ Gotenberg API is available at http://localhost:3
$ composer require php-http/guzzle6-adapter
 
-

Then the PHP client:

+

Then the PHP client:

$ composer require thecodingmachine/gotenberg-php-client
 
+

See also the example from the README.

+

Community clients

@@ -264,6 +284,22 @@ about what’s going on.

This environment variable accepts any string that can be turned into a port number.

+

Root path

+ +

By default, the API root path is /.

+ +

You may customize this value with the environment variable ROOT_PATH.

+ +

This environment variable accepts a string starting and ending with /.

+ +

For instance, /gotenberg/ is a valid value while gotenberg is not.

+ +
+

This is useful if you wish to do service discovery via URL paths.

+
+

Disable Google Chrome

@@ -421,14 +457,13 @@ which will be converted to PDF.

Go -
import "github.com/thecodingmachine/gotenberg-go-client/v6"
+
import "github.com/thecodingmachine/gotenberg-go-client/v7"
 
-func main() {
-    c := &gotenberg.Client{Hostname: "http://localhost:3000"}
-    req, _ := gotenberg.NewHTMLRequest("index.html")
-    dest := "result.pdf"
-    c.Store(req, dest)
-}
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file")
+req := gotenberg.NewHTMLRequest(index)
+dest := "result.pdf"
+c.Store(req, dest)
 

Go -
import "github.com/thecodingmachine/gotenberg-go-client/v6"
+
import "github.com/thecodingmachine/gotenberg-go-client/v7"
 
-func main() {
-    c := &gotenberg.Client{Hostname: "http://localhost:3000"}
-    req, _ := gotenberg.NewHTMLRequest("index.html")
-    req.Header("header.html")
-    req.Footer("footer.html")
-    dest := "result.pdf"
-    c.Store(req, dest)
-}
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file")
+header, _ := gotenberg.NewDocumentFromPath("header.html", "/path/to/file")
+footer, _ := gotenberg.NewDocumentFromPath("footer.html", "/path/to/file")
+req := gotenberg.NewHTMLRequest(index)
+req.Header(header)
+req.Footer(footer)
+dest := "result.pdf"
+c.Store(req, dest)
 

fonts section.

Go -
import "github.com/thecodingmachine/gotenberg-go-client/v6"
+
import "github.com/thecodingmachine/gotenberg-go-client/v7"
 
-func main() {
-    c := &gotenberg.Client{Hostname: "http://localhost:3000"}
-    req, _ := gotenberg.NewHTMLRequest("index.html")
-    req.Assets("font.woff", "img.gif", "style.css")
-    dest := "result.pdf"
-    c.Store(req, dest)
-}
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file")
+style, _ := gotenberg.NewDocumentFromPath("style.css", "/path/to/file")
+img, _ := gotenberg.NewDocumentFromPath("img.png", "/path/to/file")
+font, _ := gotenberg.NewDocumentFromPath("font.woff", "/path/to/file")
+req := gotenberg.NewHTMLRequest(index)
+req.Assets(style, img, font)
+dest := "result.pdf"
+c.Store(req, dest)
 

Go -
import "github.com/thecodingmachine/gotenberg-go-client/v6"
+
import "github.com/thecodingmachine/gotenberg-go-client/v7"
 
-func main() {
-    c := &gotenberg.Client{Hostname: "http://localhost:3000"}
-    req, _ := gotenberg.NewHTMLRequest("index.html")
-    req.PaperSize(gotenberg.A4)
-    req.Margins(gotenberg.NoMargins)
-    req.Landscape(true)
-    dest := "result.pdf"
-    c.Store(req, dest)
-}
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file")
+req := gotenberg.NewHTMLRequest(index)
+req.PaperSize(gotenberg.A4)
+req.Margins(gotenberg.NoMargins)
+req.Landscape(true)
+dest := "result.pdf"
+c.Store(req, dest)
 

Page ranges

+ +

You may specify the page ranges to convert.

+ +

The format is the same as the one from the print options +of Google Chrome, e.g. 1-5,8,11-13.

+ +

cURL

+ +
$ curl --request POST \
+    --url http://localhost:3000/convert/html \
+    --header 'Content-Type: multipart/form-data' \
+    --form files=@index.html \
+    --form pageRanges='1-3,5' \
+    -o result.pdf
+
+ +

Go

+ +
import "github.com/thecodingmachine/gotenberg-go-client/v7"
+
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file")
+req := gotenberg.NewHTMLRequest(index)
+req.PageRanges("1-3,5")
+dest := "result.pdf"
+c.Store(req, dest)
+
+ +

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', '/path/to/file');
+$request = new HTMLRequest($index);
+$request->setPageRanges('1-3,5');
+$dest = 'result.pdf';
 $client->store($request, $dest);
 
@@ -723,7 +812,7 @@ a lot on JavaScript for rendering.

--url http://localhost:3000/convert/html \ --header 'Content-Type: multipart/form-data' \ --form files=@index.html \ - --form waitDelay=5.5 \ + --form waitDelay=5.5 \ -o result.pdf
@@ -731,15 +820,14 @@ a lot on JavaScript for rendering.

Go -
import "github.com/thecodingmachine/gotenberg-go-client/v6"
+
import "github.com/thecodingmachine/gotenberg-go-client/v7"
 
-func main() {
-    c := &gotenberg.Client{Hostname: "http://localhost:3000"}
-    req, _ := gotenberg.NewHTMLRequest("index.html")
-    req.WaitDelay(5.5)
-    dest := "result.pdf"
-    c.Store(req, dest)
-}
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file")
+req := gotenberg.NewHTMLRequest(index)
+req.WaitDelay(5.5)
+dest := "result.pdf"
+c.Store(req, dest)
 

Go -
import "github.com/thecodingmachine/gotenberg-go-client/v6"
+
import "github.com/thecodingmachine/gotenberg-go-client/v7"
 
-func main() {
-    c := &gotenberg.Client{Hostname: "http://localhost:3000"}
-    req, _ := gotenberg.NewHTMLRequest("index.html")
-    req.GoogleChromeRpccBufferSize(1048576)
-    dest := "result.pdf"
-    c.Store(req, dest)
-}
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file")
+req := gotenberg.NewHTMLRequest(index)
+req.GoogleChromeRpccBufferSize(1048576)
+dest := "result.pdf"
+c.Store(req, dest)
 

Go -
import "github.com/thecodingmachine/gotenberg-go-client/v6"
+
import "github.com/thecodingmachine/gotenberg-go-client/v7"
 
-func main() {
-    c := &gotenberg.Client{Hostname: "http://localhost:3000"}
-    req := gotenberg.NewURLRequest("https://google.com")
-    req.Margins(gotenberg.NoMargins)
-    dest := "result.pdf"
-    c.Store(req, dest)
-}
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+req := gotenberg.NewURLRequest("https://google.com")
+req.Margins(gotenberg.NoMargins)
+dest := "result.pdf"
+c.Store(req, dest)
 

Custom HTTP headers

+ +

You may send your own HTTP headers to the remoteURL.

+ +

For instance, by adding the HTTP header Gotenberg-Remoteurl-Your-Header to your request, +the API will send a request to the remoteURL with the HTTP header Your-Header.

+ +
+

Attention: the API uses a canonical format for the HTTP headers: +it transforms the first +letter and any letter following a hyphen to upper case; +the rest are converted to lowercase. For example, the +canonical key for accept-encoding is Accept-Encoding.

+
+ +

cURL

+ +
$ curl --request POST \
+    --url http://localhost:3000/convert/url \
+    --header 'Content-Type: multipart/form-data' \
+    --header 'Gotenberg-Remoteurl-Your-Header: Foo' \
+    --form remoteURL=https://google.com \
+    -o result.pdf
+
+ +

Go

+ +
import "github.com/thecodingmachine/gotenberg-go-client/v7"
+
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+req := gotenberg.NewURLRequest("https://google.com")
+req.AddRemoteURLHTTPHeader("Your-Header", "Foo")
+dest := "result.pdf"
+c.Store(req, dest)
+
+ +

PHP

+ +
use TheCodingMachine\Gotenberg\Client;
+use TheCodingMachine\Gotenberg\URLRequest;
+
+$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client());
+$request = new URLRequest('https://google.com');
+$request->addRemoteURLHTTPHeader('Your-Header', 'Foo')
+$dest = 'result.pdf';
 $client->store($request, $dest);
 
@@ -933,14 +1074,14 @@ in the file index.html. This function will convert a given markdown Go -
import "github.com/thecodingmachine/gotenberg-go-client/v6"
+
import "github.com/thecodingmachine/gotenberg-go-client/v7"
 
-func main() {
-    c := &gotenberg.Client{Hostname: "http://localhost:3000"}
-    req, _ := gotenberg.NewMarkdownRequest("index.html", "file.md")
-    dest := "result.pdf"
-    c.Store(req, dest)
-}
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file")
+markdown, _ := gotenberg.NewDocumentFromPath("file.md", "/path/to/file")
+req := gotenberg.NewMarkdownRequest(index, markdown)
+dest := "result.pdf"
+c.Store(req, dest)
 

Go -
import "github.com/thecodingmachine/gotenberg-go-client/v6"
+
import "github.com/thecodingmachine/gotenberg-go-client/v7"
 
-func main() {
-    c := &gotenberg.Client{Hostname: "http://localhost:3000"}
-    req, _ := gotenberg.NewOfficeRequest("document.docx", "document2.docx")
-    dest := "result.pdf"
-    c.Store(req, dest)
-}
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+doc, _ := gotenberg.NewDocumentFromPath("document.docx", "/path/to/file")
+doc2, _ := gotenberg.NewDocumentFromPath("document2.docx", "/path/to/file")
+req := gotenberg.NewOfficeRequest(doc, doc2)
+dest := "result.pdf"
+c.Store(req, dest)
 

Go -
import "github.com/thecodingmachine/gotenberg-go-client/v6"
+
import "github.com/thecodingmachine/gotenberg-go-client/v7"
 
-func main() {
-    c := &gotenberg.Client{Hostname: "http://localhost:3000"}
-    req, _ := gotenberg.NewOfficeRequest("document.docx")
-    req.Landscape(true)
-    dest := "result.pdf"
-    c.Store(req, dest)
-}
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+doc, _ := gotenberg.NewDocumentFromPath("document.docx", "/path/to/file")
+req := gotenberg.NewOfficeRequest(doc)
+req.Landscape(true)
+dest := "result.pdf"
+c.Store(req, dest)
 

Page ranges

+ +

You may specify the page ranges to convert.

+ +

The format is the same as the one from the print options +of LibreOffice, e.g. 1-1 or 1-4.

+ +
+

Attention: if more than one document, the page ranges will be +applied for each document.

+
+ +

cURL

+ +
$ curl --request POST \
+    --url http://localhost:3000/convert/office \
+    --header 'Content-Type: multipart/form-data' \
+    --form files=@document.docx \
+    --form pageRanges='1-3' \
+    -o result.pdf
+
+ +

Go

+ +
import "github.com/thecodingmachine/gotenberg-go-client/v7"
+
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+doc, _ := gotenberg.NewDocumentFromPath("document.docx", "/path/to/file")
+req := gotenberg.NewOfficeRequest(doc)
+req.PageRanges("1-3")
+dest := "result.pdf"
+c.Store(req, dest)
+
+ +

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', '/path/to/file'),
+];
+$request = new OfficeRequest($files);
+$request->setPageRanges('1-3');
+$dest = 'result.pdf';
 $client->store($request, $dest);
 
@@ -1132,14 +1330,14 @@ will merge them and return the resulting PDF file.

Go -
import "github.com/thecodingmachine/gotenberg-go-client/v6"
+
import "github.com/thecodingmachine/gotenberg-go-client/v7"
 
-func main() {
-    c := &gotenberg.Client{Hostname: "http://localhost:3000"}
-    req, _ := gotenberg.NewMergeRequest("file.pdf", "file2.pdf")
-    dest := "result.pdf"
-    c.Store(req, dest)
-}
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+pdf, _ := gotenberg.NewDocumentFromPath("file.pdf", "/path/to/file")
+pdf2, _ := gotenberg.NewDocumentFromPath("file2.pdf", "/path/to/file")
+req := gotenberg.NewMergeRequest(pdf, pdf2)
+dest := "result.pdf"
+c.Store(req, dest)
 

Go

-
import "github.com/thecodingmachine/gotenberg-go-client/v6"
+
import "github.com/thecodingmachine/gotenberg-go-client/v7"
 
-func main() {
-    c := &gotenberg.Client{Hostname: "http://localhost:3000"}
-    req, _ := gotenberg.NewHTMLRequest("index.html")
-    req.WaitTimeout(2.5)
-    resp, _ := c.Post(req)
-}
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file")
+req := gotenberg.NewHTMLRequest(index)
+req.WaitTimeout(2.5)
+resp, _ := c.Post(req)
 

Go -
import "github.com/thecodingmachine/gotenberg-go-client/v6"
+
import "github.com/thecodingmachine/gotenberg-go-client/v7"
 
-func main() {
-    c := &gotenberg.Client{Hostname: "http://localhost:3000"}
-    req, _ := gotenberg.NewHTMLRequest("index.html")
-    req.WebhookURL("http://myapp.com/webhook/")
-    resp, _ := c.Post(req)
-}
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file")
+req := gotenberg.NewHTMLRequest(index)
+req.WebhookURL("http://myapp.com/webhook/")
+resp, _ := c.Post(req)
 

environment variables section.

-

Examples

- -

cURL

+cURL
$ curl --request POST \
     --url http://localhost:3000/convert/html \
     --header 'Content-Type: multipart/form-data' \
     --form files=@index.html \
     --form webhookURL='http://myapp.com/webhook/' \
-    --form webhookURLTimeout=2.5
+    --form webhookURLTimeout=2.5
 
-

Go

+Go

-
import "github.com/thecodingmachine/gotenberg-go-client/v6"
+
import "github.com/thecodingmachine/gotenberg-go-client/v7"
 
-func main() {
-    c := &gotenberg.Client{Hostname: "http://localhost:3000"}
-    req, _ := gotenberg.NewHTMLRequest("index.html")
-    req.WebhookURL("http://myapp.com/webhook/")
-    req.WebhookURLTimeout(2.5)
-    resp, _ := c.Post(req)
-}
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file")
+req := gotenberg.NewHTMLRequest(index)
+req.WebhookURL("http://myapp.com/webhook/")
+req.WebhookURLTimeout(2.5)
+resp, _ := c.Post(req)
 
-

PHP

+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');
+$index = DocumentFactory::makeFromPath('index.html', '/path/to/file');
 $request = new HTMLRequest($index);
 $request->setWebhookURL('http://myapp.com/webhook/');
 $request->setWebhookURLTimeout(2.5);
 $resp = $client->post($request);
+
+ +

Custom HTTP headers

+ +

You may send your own HTTP headers to the webhookURL.

+ +

For instance, by adding the HTTP header Gotenberg-Webhookurl-Your-Header to your request, +the API will send a request to the webhookURL with the HTTP header Your-Header.

+ +
+

Attention: the API uses a canonical format for the HTTP headers: +it transforms the first +letter and any letter following a hyphen to upper case; +the rest are converted to lowercase. For example, the +canonical key for accept-encoding is Accept-Encoding.

+
+ +

cURL

+ +
$ curl --request POST \
+    --url http://localhost:3000/convert/html \
+    --header 'Content-Type: multipart/form-data' \
+    --header 'Gotenberg-Webhookurl-Your-Header: Foo' \
+    --form files=@index.html \
+    --form webhookURL='http://myapp.com/webhook/'
+
+ +

Go

+ +
import "github.com/thecodingmachine/gotenberg-go-client/v7"
+
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file")
+req := gotenberg.NewHTMLRequest(index)
+req.WebhookURL("http://myapp.com/webhook/")
+req.AddWebhookURLHTTPHeader("Your-Header", "Foo")
+resp, _ := c.Post(req)
+
+ +

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', '/path/to/file');
+$request = new HTMLRequest($index);
+$request->setWebhookURL('http://myapp.com/webhook/');
+$request->addWebhookURLHTTPHeader('Your-Header', 'Foo');
+$resp = $client->post($request);
 
@@ -1375,14 +1625,13 @@ Otherwise a random filename is used.

Go -
import "github.com/thecodingmachine/gotenberg-go-client/v6"
+
import "github.com/thecodingmachine/gotenberg-go-client/v7"
 
-func main() {
-    c := &gotenberg.Client{Hostname: "http://localhost:3000"}
-    req, _ := gotenberg.NewHTMLRequest("index.html")
-    req.ResultFilename("foo.pdf")
-    resp, _ := c.Post(req)
-}
+c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+index, _ := gotenberg.NewDocumentFromPath("index.html", "/path/to/file")
+req := gotenberg.NewHTMLRequest(index)
+req.ResultFilename("foo.pdf")
+resp, _ := c.Post(req)