diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..191381ee --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.git \ No newline at end of file diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md deleted file mode 100644 index 1165dd4e..00000000 --- a/.github/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,46 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment include: - -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery and unwelcome sexual attention or advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at neuhart.julien@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] - -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md deleted file mode 100644 index 624d84f8..00000000 --- a/.github/CONTRIBUTING.md +++ /dev/null @@ -1,39 +0,0 @@ -# Contributing - -Hi! Thank you for considering contributing to Gotenberg. You'll -find below useful information about how to contribute to the Gotenberg project. - -## Contributing code - -### Install from sources - -1. Install and run the latest version of Docker -2. Verify your Go version (>= 1.14) -3. Fork this repository -4. Clone it outside of your `GOPATH` (we're using Go modules) - -### Working with git - -1. Create your feature branch (`git checkout -b my-new-feature`) -2. Commit your changes (`git commit -am 'Add some feature'`) -3. Push to the branch (`git push origin my-new-feature`) -4. Create a new pull request - -### Testing - -1. Run all linters (`make lint`) -2. Run all tests (`make tests`) - -## Reporting bugs and feature request - -Your issue or feature request may already be reported! -Please search on the [issue tracker](../../../issues) before creating one. - -If you do not find any relevant issue or feature request, feel free to -add a new one! - -## Additional resources - -* [Code of conduct](CODE_OF_CONDUCT.md) -* [Issue template](ISSUE_TEMPLATE.md) -* [Pull request template](PULL_REQUEST_TEMPLATE.md) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index fe595d44..00000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,35 +0,0 @@ -Your issue may already be reported! -Please search on the [issue tracker](../../../issues) before creating one. - -## Expected Behavior - - - -## Current Behavior - - - -## Possible Solution - - - -## Steps to Reproduce (for bugs) - - -1. -2. -3. -4. - -## Logs (LOG_LEVEL="DEBUG") - - -## Context - - - -## Your Environment - -* Version used: -* Operating System and version: -* Link to your project: diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e768c49b..00000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,45 +0,0 @@ -A similar PR may already be submitted! -Please search among the [pull requests](../../../pulls) before creating one. - -Thanks for submitting a pull request! Please provide enough information so that others can review your pull request: - -For more information, see the [CONTRIBUTING](CONTRIBUTING.md) guide. - -**Summary** - - - -This PR fixes/implements the following **bugs/features** - -* [ ] Bug 1 -* [ ] Bug 2 -* [ ] Feature 1 -* [ ] Feature 2 -* [ ] Breaking changes - - - -Explain the **motivation** for making this change. What existing problem does the pull request solve? - - - -**Test plan (required)** - -Demonstrate the code is solid. Example: The exact commands you ran and their output. - - - -**Closing issues** - - -Fixes # - -**Checklist** - -- [ ] Have you followed the guidelines in our [CONTRIBUTING](CONTRIBUTING.md) guide? -- [ ] Have you lint your code locally prior to submission (`make lint`)? -- [ ] Have you written new tests for your core changes, as applicable? -- [ ] Have you successfully ran tests with your changes locally (`make tests`)? -- [ ] Have you updated the documentation (Markdown files under `build > docs > content` and then `make doc`)? -- [ ] I have squashed any insignificant commits -- [ ] This change has comments for package types, values, functions, and non-obvious lines of code diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 1fa95085..00000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,32 +0,0 @@ -version: 2 -updates: -- package-ecosystem: gomod - directory: "/" - schedule: - interval: daily - time: "04:00" - open-pull-requests-limit: 10 - ignore: - - dependency-name: github.com/microcosm-cc/bluemonday - versions: - - 1.0.4 - - 1.0.5 - - 1.0.6 - - 1.0.7 - - 1.0.8 - - dependency-name: golang.org/x/text - versions: - - 0.3.5 - - dependency-name: github.com/labstack/echo/v4 - versions: - - 4.1.17 - - 4.2.0 - - 4.2.1 - - dependency-name: github.com/sirupsen/logrus - versions: - - 1.7.0 - - 1.7.1 - - 1.8.0 - - dependency-name: github.com/mafredri/cdp - versions: - - 0.30.0 diff --git a/.github/workflows/continuous_delivery.yml b/.github/workflows/continuous_delivery.yml new file mode 100644 index 00000000..7f7b44ee --- /dev/null +++ b/.github/workflows/continuous_delivery.yml @@ -0,0 +1,27 @@ +name: Continuous Delivery + +on: + release: + types: [ published ] + +jobs: + + release: + name: Release Docker image + runs-on: ubuntu-latest + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Checkout source code + uses: actions/checkout@v2 + - name: Log in to Docker Hub Container Registry + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push Docker image + run: | + make release GOTENBERG_VERSION=${{ github.event.release.tag_name }} + make release GOTENBERG_VERSION=${{ github.event.release.tag_name }} DOCKER_REGISTRY=thecodingmachine diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml new file mode 100644 index 00000000..e130c413 --- /dev/null +++ b/.github/workflows/continuous_integration.yml @@ -0,0 +1,43 @@ +name: Continuous Integration + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout source code + uses: actions/checkout@v2 + - name: Run linters + uses: golangci/golangci-lint-action@v2 + with: + version: v1.39 + + tests: + needs: + - Lint + name: Tests + # TODO: once arm64 actions are available, also run the tests on this architecture. + # See: https://github.com/actions/virtual-environments/issues/2552#issuecomment-771478000. + runs-on: ubuntu-latest + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Checkout source code + uses: actions/checkout@v2 + - name: Build testing environment + run: make build build-tests + - name: Run tests + run: | + make tests-once + bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/.github/workflows/tests_maybe_release.yml b/.github/workflows/tests_maybe_release.yml deleted file mode 100644 index b562239a..00000000 --- a/.github/workflows/tests_maybe_release.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: tests_maybe_release - -on: - push: - pull_request: - release: - types: [published] - -jobs: - tests_maybe_release: - runs-on: ubuntu-latest - steps: - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - uses: actions/checkout@v1 - - name: Lint code - run: make lint - - name: Run tests - run: | - make tests CODE_COVERAGE=1 - bash <(curl -s https://codecov.io/bash) - - name: Release - if: ${{ github.event_name == 'release' }} - run: make publish VERSION=${{ github.event.release.tag_name }} DOCKER_USER=${{ secrets.DOCKER_USER }} DOCKER_PASSWORD=${{ secrets.DOCKER_PASSWORD }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3c56ae0d..24fd0f00 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -.idea -coverage.txt \ No newline at end of file +/coverage.html +/coverage.txt \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..db948573 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,30 @@ +linters: + disable-all: true + enable: + - bodyclose + - deadcode + - errcheck + - gofmt + - goimports + - gosec + - gosimple + - govet + - ineffassign + - misspell + - prealloc + - staticcheck + - structcheck + - typecheck + - unconvert + - unused + - varcheck + +run: + deadline: 5m + issues-exit-code: 1 + tests: false + +output: + format: 'colored-line-number' + print-issued-lines: true + print-linter-name: true \ No newline at end of file diff --git a/LICENSE b/LICENSE index b756c5a5..cc678f87 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 TheCodingMachine +Copyright (c) 2021 Julien Neuhart Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile index 4478b495..3d2203fb 100644 --- a/Makefile +++ b/Makefile @@ -1,66 +1,133 @@ -GOLANG_VERSION=1.14 -VERSION=snapshot -DOCKER_USER= -DOCKER_PASSWORD= -DOCKER_REGISTRY=thecodingmachine +.PHONY: help +help: ## Show the help + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +.PHONY: it +it: build build-tests ## Initialize the development environment + +GOLANG_VERSION=1.16 +DOCKER_REGISTRY=gotenberg +GOTENBERG_VERSION=snapshot GOTENBERG_USER_GID=1001 GOTENBERG_USER_UID=1001 -GOLANGCI_LINT_VERSION=1.27.0 -CODE_COVERAGE=0 -TINI_VERSION=0.19.0 -MAXIMUM_WAIT_TIMEOUT=30.0 -MAXIMUM_WAIT_DELAY=10.0 -MAXIMUM_WEBHOOK_URL_TIMEOUT=30.0 -DEFAULT_WAIT_TIMEOUT=10.0 -DEFAULT_WEBHOOK_URL_TIMEOUT=10.0 -DEFAULT_LISTEN_PORT=3000 -DISABLE_GOOGLE_CHROME=0 -DISABLE_UNOCONV=0 -LOG_LEVEL=INFO -ROOT_PATH=/ -DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE=1048576 -GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS=0 +PDFTK_VERSION=1353200058 # See https://gitlab.com/pdftk-java/pdftk/-/releases - Binary package. +GOLANGCI_LINT_VERSION=v1.39.0 # See https://github.com/golangci/golangci-lint/releases. -# build the base Docker image. -base: - 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 . +.PHONY: build +build: ## Build the Gotenberg's Docker image + docker build \ + --build-arg GOLANG_VERSION=$(GOLANG_VERSION) \ + --build-arg GOTENBERG_VERSION=$(GOTENBERG_VERSION) \ + --build-arg GOTENBERG_USER_GID=$(GOTENBERG_USER_GID) \ + --build-arg GOTENBERG_USER_UID=$(GOTENBERG_USER_UID) \ + --build-arg PDFTK_VERSION=$(PDFTK_VERSION) \ + -t $(DOCKER_REGISTRY)/gotenberg:$(GOTENBERG_VERSION) \ + -f build/Dockerfile . -# build the workspace Docker image. -workspace: - make base - docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) -t $(DOCKER_REGISTRY)/gotenberg:workspace -f build/workspace/Dockerfile . +GOTENBERG_GRACEFUL_SHUTDOWN_DURATION=30s +API_PORT=3000 +API_PORT_FROM_ENV= +API_READ_TIMEOUT=30s +API_PROCESS_TIMEOUT=30s +API_WRITE_TIMEOUT=30s +API_ROOT_PATH=/ +API_TRACE_HEADER=Gotenberg-Trace +API_DISABLE_HEALTH_CHECK_LOGGING=false +API_WEBHOOK_ALLOW_LIST= +API_WEBHOOK_DENY_LIST= +API_WEBHOOK_ERROR_ALLOW_LIST= +API_WEBHOOK_ERROR_DENY_LIST= +API_WEBHOOK_MAX_RETRY=4 +API_WEBHOOK_RETRY_MIN_WAIT=1s +API_WEBHOOK_RETRY_MAX_WAIT=30s +API_DISABLE_WEBHOOK=false +CHROMIUM_USER_AGENT= +CHROMIUM_INCOGNITO=false +CHROMIUM_IGNORE_CERTIFICATE_ERRORS=false +CHROMIUM_ALLOW_LIST= +CHROMIUM_DENY_LIST="^file:///[^tmp].*" +CHROMIUM_DISABLE_ROUTES=false +LIBREOFFICE_DISABLES_ROUTES=false +LOG_LEVEL=info +LOG_FORMAT=auto +PDFENGINES_ENGINES= +PDFENGINES_DISABLE_ROUTES=false -# gofmt and goimports all go files. -fmt: +.PHONY: run +run: ## Start a Gotenberg container + docker run --rm -it \ + -p $(API_PORT):$(API_PORT) \ + $(DOCKER_REGISTRY)/gotenberg:$(GOTENBERG_VERSION) \ + gotenberg \ + --gotenberg-graceful-shutdown-duration=$(GOTENBERG_GRACEFUL_SHUTDOWN_DURATION) \ + --api-port=$(API_PORT) \ + --api-port-from-env=$(API_PORT_FROM_ENV) \ + --api-read-timeout=$(API_READ_TIMEOUT) \ + --api-process-timeout=$(API_PROCESS_TIMEOUT) \ + --api-write-timeout=$(API_WRITE_TIMEOUT) \ + --api-root-path=$(API_ROOT_PATH) \ + --api-trace-header=$(API_TRACE_HEADER) \ + --api-disable-health-check-logging=$(API_DISABLE_HEALTH_CHECK_LOGGING) \ + --api-webhook-allow-list=$(API_WEBHOOK_ALLOW_LIST) \ + --api-webhook-deny-list=$(API_WEBHOOK_DENY_LIST) \ + --api-webhook-error-allow-list=$(API_WEBHOOK_ERROR_ALLOW_LIST) \ + --api-webhook-error-deny-list=$(API_WEBHOOK_ERROR_DENY_LIST) \ + --api-webhook-max-retry=$(API_WEBHOOK_MAX_RETRY) \ + --api-webhook-retry-min-wait=$(API_WEBHOOK_RETRY_MIN_WAIT) \ + --api-webhook-retry-max-wait=$(API_WEBHOOK_RETRY_MAX_WAIT) \ + --api-disable-webhook=$(API_DISABLE_WEBHOOK) \ + --chromium-user-agent=$(CHROMIUM_USER_AGENT) \ + --chromium-incognito=$(CHROMIUM_INCOGNITO) \ + --chromium-ignore-certificate-errors=$(CHROMIUM_IGNORE_CERTIFICATE_ERRORS) \ + --chromium-allow-list=$(CHROMIUM_ALLOW_LIST) \ + --chromium-deny-list=$(CHROMIUM_DENY_LIST) \ + --chromium-disable-routes=$(CHROMIUM_DISABLE_ROUTES) \ + --libreoffice-disable-routes=$(LIBREOFFICE_DISABLES_ROUTES) \ + --log-level=$(LOG_LEVEL) \ + --log-format=$(LOG_FORMAT) \ + --pdfengines-engines=$(PDFENGINES_ENGINES) \ + --pdfengines-disable-routes=$(PDFENGINES_DISABLE_ROUTES) + +.PHONY: build-tests +build-tests: ## Build the tests' Docker image + docker build \ + --build-arg GOLANG_VERSION=$(GOLANG_VERSION) \ + --build-arg DOCKER_REGISTRY=$(DOCKER_REGISTRY) \ + --build-arg GOTENBERG_VERSION=$(GOTENBERG_VERSION) \ + --build-arg GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION) \ + -t $(DOCKER_REGISTRY)/gotenberg:$(GOTENBERG_VERSION)-tests \ + -f test/Dockerfile . + +.PHONY: tests +tests: ## Start the testing environment + docker run --rm -it \ + -v $(PWD):/tests \ + $(DOCKER_REGISTRY)/gotenberg:$(GOTENBERG_VERSION)-tests \ + bash + +.PHONY: tests-once +tests-once: ## Run the tests once (prefer the "tests" command while developing) + docker run --rm \ + -v $(PWD):/tests \ + $(DOCKER_REGISTRY)/gotenberg:$(GOTENBERG_VERSION)-tests \ + gotest + +.PHONY: fmt +fmt: ## Format the code and "optimize" the dependencies go fmt ./... go mod tidy -# run all linters. -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 +.PHONY: godoc +godoc: ## Run a webserver with Gotenberg godoc (go get golang.org/x/tools/cmd/godoc) + $(info http://localhost:6060/pkg/github.com/gotenberg/gotenberg/v7) + godoc -http=:6060 -# run all tests. -tests: - make workspace - ./scripts/tests.sh $(DOCKER_REGISTRY) $(CODE_COVERAGE) - -# generate documentation. -doc: - make workspace - 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_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 ROOT_PATH=$(ROOT_PATH) -e DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE=$(DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE) -e GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS=$(GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS) -p "$(DEFAULT_LISTEN_PORT):$(DEFAULT_LISTEN_PORT)" $(DOCKER_REGISTRY)/gotenberg:$(VERSION) - -# publish Gotenberg images according to version. -publish: - make workspace - ./scripts/publish.sh $(GOLANG_VERSION) $(TINI_VERSION) $(DOCKER_REGISTRY) $(VERSION) $(DOCKER_USER) $(DOCKER_PASSWORD) \ No newline at end of file +.PHONY: release +release: ## Build the Gotenberg's Docker image for linux/amd64 and linux/arm64 platforms, then push it to a Docker Registry + ./scripts/release.sh \ + $(GOLANG_VERSION) \ + $(GOTENBERG_VERSION) \ + $(GOTENBERG_USER_GID) \ + $(GOTENBERG_USER_UID) \ + $(PDFTK_VERSION) \ + $(DOCKER_REGISTRY) diff --git a/README.md b/README.md index 89d1bf7b..08553b0f 100644 --- a/README.md +++ b/README.md @@ -1,45 +1,46 @@
-
-
A Docker-powered stateless API for converting HTML, Markdown and Office documents to PDF.
- +A Docker-powered stateless API for PDF files
+ --- -At TheCodingMachine, we build a lot of web applications (intranets, extranets and so on) which require to generate PDF from various sources. Each time, we ended up using some well known libraries and kind of lost time by reimplementing a solution from a project to another project. Meh. +Gotenberg provides a developer-friendly API to interact with powerful tools like Chromium and LibreOffice to convert many +documents to PDF, transform them, merge them, and more! -## Features - -* HTML and Markdown conversions using Google Chrome headless -* Office conversions (.txt, .rtf, .docx, .doc, .odt, .pptx, .ppt, .odp and so on) using [unoconv](https://github.com/dagwieers/unoconv) -* Assets :package:: send your header, footer, images, fonts, stylesheets and so on for converting your HTML and Markdown to beautiful PDFs! -* Easily interact with the API using our [Go](https://github.com/thecodingmachine/gotenberg-go-client) and [PHP](https://github.com/thecodingmachine/gotenberg-php-client) libraries - -## Quick start +## Quick Start Open a terminal and run the following command: -```bash -$ docker run --rm -p 3000:3000 thecodingmachine/gotenberg:6 +``` +docker run --rm -p 3000:3000 gotenberg/gotenberg:7 ``` -The API is now available on your host at `http://localhost:3000`. +Alternatively, using the historic Docker registry from our sponsor [TheCodingMachine](https://www.thecodingmachine.com): -Head to the [documentation](https://gotenberg.dev/) -to learn how to interact with it! +``` +docker run --rm -p 3000:3000 thecodingmachine/gotenberg:7 +``` + +The API is now available on your host at http://localhost:3000. + +Head to the [documentation](https://gotenberg.dev/docs/about) to learn how to interact with it 🚀 + +## Sponsors + +
+
+
+
+
-
-
- of -
- - -``` - -The following classes allow you to inject printing values: - -* `date`: formatted print date -* `title`: document title -* `pageNumber`: current page number -* `totalPage`: total pages in the document - -There are some limitations: - -* JavaScript is not executed -* external resources are not loaded -* the CSS properties are independant of the ones used in the `index.html` file -* `footer.html` CSS properties override the ones from `header.html` -* only fonts installed in the Docker image are loaded (see the [fonts section](#fonts)) -* images only work using a `base64` encoded source (`
-
-
-```
-
-But this won't:
-
-```html
-
-
-
-
-
-
-
-```
-
-You may also use *remote* paths for Google fonts, images and so on.
-
-> If you want to install fonts directly in the Gotenberg Docker image,
-> see to the [fonts section](#fonts).
-
-### cURL
-
-```bash
-$ curl --request POST \
- --url http://localhost:3000/convert/html \
- --header 'Content-Type: multipart/form-data' \
- --form files=@index.html \
- --form files=@style.css \
- --form files=@img.png \
- --form files=@font.woff \
- -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")
-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
-
-```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');
-$assets = [
- 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';
-$client->store($request, $dest);
-```
-
-## Paper size, margins, orientation, scaling
-
-You may also customize the resulting PDF format.
-
-By default, it will be rendered with `A4` size, `1 inch` margins and `portrait` orientation and 100% (`1.0`) page scale.
-
-> Paper size and margins have to be provided in `inches`. Same for margins.
-
-### cURL
-
-```bash
-$ curl --request POST \
- --url http://localhost:3000/convert/html \
- --header 'Content-Type: multipart/form-data' \
- --form files=@index.html \
- --form paperWidth=8.27 \
- --form paperHeight=11.69 \
- --form marginTop=0 \
- --form marginBottom=0 \
- --form marginLeft=0 \
- --form marginRight=0 \
- --form landscape=true \
- --form scale=0.75 \
- -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.PaperSize(gotenberg.A4)
-req.Margins(gotenberg.NoMargins)
-req.Landscape(true)
-req.Scale(0.75)
-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->setPaperSize(Request::A4);
-$request->setMargins(Request::NO_MARGINS);
-$request->setLandscape(true);
-$request->setScale(0.75);
-$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);
-```
-
-## Wait delay
-
-In some cases, you may want to wait a certain amount of time to make sure the
-page you're trying to generate is fully rendered. For instance, if your page relies
-a lot on JavaScript for rendering.
-
-> The wait delay is a duration in **seconds** (e.g `2.5` for 2.5 seconds).
-
-### cURL
-
-```bash
-$ curl --request POST \
- --url http://localhost:3000/convert/html \
- --header 'Content-Type: multipart/form-data' \
- --form files=@index.html \
- --form waitDelay=5.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.WaitDelay(5.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->setWaitDelay(5.5);
-$dest = 'result.pdf';
-$client->store($request, $dest);
-```
-
-## Rpcc buffer size
-
-The API might return a `400` HTTP code with the message `increase the Google Chrome rpcc buffer size`.
-
-If so, you may increase this buffer size with a form field named `googleChromeRpccBufferSize`.
-
-It takes an int as value (e.g. `1048576` for 1 MB).
-The hard limit is 100 MB and is defined by Google Chrome itself.
-
-> You may also define this value globally: see the [environment variables](#environment_variables.default_google_chrome_rpcc_buffer_size) section.
-
-### cURL
-
-```bash
-$ curl --request POST \
- --url http://localhost:3000/convert/html \
- --header 'Content-Type: multipart/form-data' \
- --form files=@index.html \
- --form googleChromeRpccBufferSize=1048576 \
- -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.GoogleChromeRpccBufferSize(1048576)
-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->setGoogleChromeRpccBufferSize(1048576);
-$dest = 'result.pdf';
-$client->store($request, $dest);
-```
diff --git a/build/docs/content/05-url.md b/build/docs/content/05-url.md
deleted file mode 100644
index be892405..00000000
--- a/build/docs/content/05-url.md
+++ /dev/null
@@ -1,106 +0,0 @@
----
-title: URL
----
-
-Gotenberg provides the endpoint `/convert/url` for remote URL conversions.
-
-It accepts `POST` requests with a `multipart/form-data` Content-Type.
-
-## Basic
-
-This endpoint does not accept an `index.html` file nor assets files but a form field
-named `remoteURL` instead. Otherwise, URL conversions work the same as HTML conversions.
-
-> **Attention:** when converting a website to PDF, you should remove all margins.
-> If not, some of the content of the page might be hidden.
-
-> **Attention:** if you try to convert a URL from a Docker Compose service named `app` (i.e. `removeURL` = `http://app/an/entrypoint`),
-> the resulting PDF will be blank. Make sure to rename your service to avoid this issue.
-
-### cURL
-
-```bash
-$ curl --request POST \
- --url http://localhost:3000/convert/url \
- --header 'Content-Type: multipart/form-data' \
- --form remoteURL=https://google.com \
- --form marginTop=0 \
- --form marginBottom=0 \
- --form marginLeft=0 \
- --form marginRight=0 \
- -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.Margins(gotenberg.NoMargins)
-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->setMargins(Request::NO_MARGINS);
-$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
deleted file mode 100644
index 5838ea7b..00000000
--- a/build/docs/content/06-markdown.md
+++ /dev/null
@@ -1,70 +0,0 @@
----
-title: Markdown
----
-
-Gotenberg provides the endpoint `/convert/markdown` for Markdown conversions.
-
-It accepts `POST` requests with a `multipart/form-data` Content-Type.
-
-## Basic
-
-Markdown conversions work the same as HTML conversions.
-
-Only difference is that you have access to the Go template function `toHTML`
-in the file `index.html`. This function will convert a given markdown file to HTML.
-
-For instance:
-
-```html
-
-
-
-
-
-
-
Gotenberg is a Docker-powered stateless API for converting HTML, Markdown and Office documents to PDF.
- -Gotenberg is shipped within a Docker image.
- - - -You may start it with:
- -$ 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=version -- -
-- --
masterbranch is always up-to-date with the latest version of the API.
You may also add it in your Docker Compose stack:
- -version: '3' - -services: - - # your other services - - gotenberg: - image: thecodingmachine/gotenberg:6 -- -
-- -The API will be available under
-gotenberg:3000in your Docker Compose network.
It may also be deployed with Kubernetes.
- -Make sure to provide enough memory and CPU requests (for instance 512Mi and 0.2 CPU).
-- -The more resources are granted, the quicker will be the conversions.
-
In the deployment specification of the pod, also specify the uid of the user gotenberg:
securityContext: - privileged: false - runAsUser: 1001 -- -
If you’re looking for cost savings, you might be interested by Cloud Run. -However, according to some users, doing asynchronous conversion (with a webhook) might not working.
- -In the following examples, we will assume your -Gotenberg API is available at http://localhost:3000.
- -We provide clients in various languages for easing the interactions with the API.
- -$ go get -u github.com/thecodingmachine/gotenberg-go-client/v7 -- -
See also the example from the README.
- -Unless your project already has a PSR7 HttpClient, install php-http/guzzle6-adapter:
$ composer require php-http/guzzle6-adapter -- -
Then the PHP client:
- -$ composer require thecodingmachine/gotenberg-php-client -- -
See also the example from the README.
- -You may customize the API behaviour thanks to environment variables.
- -The API provides structured logging allowing you to have relevant information -about what’s going on.
- --- -If a TTY is attached, the log entries are displayed in text format with colors, otherwise in JSON format.
-
You may customize the severity of the log entries thanks to the environment variable LOG_LEVEL.
It accepts one of the following severities: "DEBUG", "INFO" (default) and "ERROR".
By default, the API will listen on port 3000.
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.
- -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.
-
In order to save some resources, the Gotenberg image accepts the environment variable DISABLE_GOOGLE_CHROME
-for disabling Google Chrome.
It takes the strings "0" or "1" as value where 1 means true
-- -If Google Chrome is disabled, the following conversions will not be available anymore: -HTML, URL and Markdown
-
When performing a HTML, URL or Markdown conversion, the API might return
-a 400 HTTP code with the message increase the Google Chrome rpcc buffer size.
If so, you may increase this buffer size with the environment variable DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE.
It takes a string representation of an int as value (e.g. "1048576" for 1 MB).
-The hard limit is 100 MB and is defined by Google Chrome itself.
-- -The default Google Chrome rpcc buffer size may also be overridden per request thanks to the form field
-googleChromeRpccBufferSize. -See the rpcc buffer size section.
When performing a URL conversion, Google Chrome will not accept certificate errors.
- -You may allow insecure connections by setting the GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS environment variable to "1".
You should be careful with this feature and only enable it in your development environment.
- -You may also disable LibreOffice (unoconv) with DISABLE_UNOCONV.
-- -If LibreOffice (unoconv) is disabled, the following conversion will not be available anymore: -Office
-
By default, the API will wait 10 seconds before it considers the conversion to be unsuccessful.
-If unsucessful, it returns a 504 HTTP code.
You may customize this timeout thanks to the environment variable DEFAULT_WAIT_TIMEOUT.
It takes a string representation of a float as value (e.g "2.5" for 2.5 seconds).
-- -The default timeout may also be overridden per request thanks to the form field
-waitTimeout. -See the timeout section.
By default, the value of the form field waitTimeout cannot be more than 30 seconds.
You may increase or decrease this limit thanks to the environment variable MAXIMUM_WAIT_TIMEOUT.
It takes a string representation of a float as value (e.g "2.5" for 2.5 seconds).
By default, the API will wait 10 seconds before it considers the sending of the resulting PDF to be unsuccessful.
- --- -See the webhook section.
-
You may customize this timeout thanks to the environment variable DEFAULT_WEBHOOK_URL_TIMEOUT.
It takes a string representation of a float as value (e.g "2.5" for 2.5 seconds).
-- -The default timeout may also be overridden per request thanks to the form field
-webhookURLTimeout. -See the webhook timeout section.
By default, the value of the form field webhookURLTimeout cannot be more than 30 seconds.
You may increase or decrease this limit thanks to the environment variable MAXIMUM_WEBHOOK_URL_TIMEOUT.
It takes a string representation of a float as value (e.g "2.5" for 2.5 seconds).
By default, the value of the form field waitDelay cannot be more than 10 seconds.
-- -See the wait delay section.
-
You may increase or decrease this limit thanks to the environment variable MAXIMUM_WAIT_DELAY.
It takes a string representation of a float as value (e.g "2.5" for 2.5 seconds).
Gotenberg provides the endpoint /convert/html for HTML conversions.
It accepts POST requests with a multipart/form-data Content-Type.
The only requirement is to send a file named index.html: it is the file
-which will be converted to PDF.
For instance:
- -<!doctype html> -<html lang="en"> - <head> - <meta charset="utf-8"> - <title>My PDF</title> - </head> - <body> - <h1>Hello world!</h1> - </body> -</html> -- -
$ curl --request POST \ - --url http://localhost:3000/convert/html \ - --header 'Content-Type: multipart/form-data' \ - --form files=@index.html \ - -o result.pdf -- -
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) -dest := "result.pdf" -c.Store(req, dest) -- -
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); -$dest = 'result.pdf'; -$client->store($request, $dest); -- -
You may also add a header and/or a footer in the resulting PDF.
-Respectively, a file named header.html and footer.html.
Each of them has to be a complete HTML document:
- -<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> -- -
The following classes allow you to inject printing values:
- -date: formatted print datetitle: document titlepageNumber: current page numbertotalPage: total pages in the documentThere are some limitations:
- -index.html filefooter.html CSS properties override the ones from header.htmlbase64 encoded source (<img src="data:image/png;base64, iVBORw0K... />)background-color and color CSS properties require an additional -webkit-print-color-adjust: exact CSS property in order to work$ curl --request POST \ - --url http://localhost:3000/convert/html \ - --header 'Content-Type: multipart/form-data' \ - --form files=@index.html \ - --form files=@header.html \ - --form files=@footer.html \ - -o result.pdf -- -
import "github.com/thecodingmachine/gotenberg-go-client/v7" - -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) -- -
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'); -$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'; -$client->store($request, $dest); -- -
You may also send additional files. For instance: images, fonts, stylesheets and so on.
- -The only requirement is to make sure that their paths
-are on the same level as the index.html file.
In other 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> -- -
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> -- -
You may also use remote paths for Google fonts, images and so on.
- --- -If you want to install fonts directly in the Gotenberg Docker image, -see to the fonts section.
-
$ curl --request POST \ - --url http://localhost:3000/convert/html \ - --header 'Content-Type: multipart/form-data' \ - --form files=@index.html \ - --form files=@style.css \ - --form files=@img.png \ - --form files=@font.woff \ - -o result.pdf -- -
import "github.com/thecodingmachine/gotenberg-go-client/v7" - -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) -- -
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'); -$assets = [ - 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'; -$client->store($request, $dest); -- -
You may also customize the resulting PDF format.
- -By default, it will be rendered with A4 size, 1 inch margins and portrait orientation and 100% (1.0) page scale.
-- -Paper size and margins have to be provided in
-inches. Same for margins.
$ curl --request POST \ - --url http://localhost:3000/convert/html \ - --header 'Content-Type: multipart/form-data' \ - --form files=@index.html \ - --form paperWidth=8.27 \ - --form paperHeight=11.69 \ - --form marginTop=0 \ - --form marginBottom=0 \ - --form marginLeft=0 \ - --form marginRight=0 \ - --form landscape=true \ - --form scale=0.75 \ - -o result.pdf -- -
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.PaperSize(gotenberg.A4) -req.Margins(gotenberg.NoMargins) -req.Landscape(true) -req.Scale(0.75) -dest := "result.pdf" -c.Store(req, dest) -- -
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->setPaperSize(Request::A4); -$request->setMargins(Request::NO_MARGINS); -$request->setLandscape(true); -$request->setScale(0.75); -$dest = 'result.pdf'; -$client->store($request, $dest); -- -
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 --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 -- -
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) -- -
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); -- -
In some cases, you may want to wait a certain amount of time to make sure the -page you’re trying to generate is fully rendered. For instance, if your page relies -a lot on JavaScript for rendering.
- --- -The wait delay is a duration in seconds (e.g
-2.5for 2.5 seconds).
$ curl --request POST \ - --url http://localhost:3000/convert/html \ - --header 'Content-Type: multipart/form-data' \ - --form files=@index.html \ - --form waitDelay=5.5 \ - -o result.pdf -- -
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.WaitDelay(5.5) -dest := "result.pdf" -c.Store(req, dest) -- -
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->setWaitDelay(5.5); -$dest = 'result.pdf'; -$client->store($request, $dest); -- -
The API might return a 400 HTTP code with the message increase the Google Chrome rpcc buffer size.
If so, you may increase this buffer size with a form field named googleChromeRpccBufferSize.
It takes an int as value (e.g. 1048576 for 1 MB).
-The hard limit is 100 MB and is defined by Google Chrome itself.
-- -You may also define this value globally: see the environment variables section.
-
$ curl --request POST \ - --url http://localhost:3000/convert/html \ - --header 'Content-Type: multipart/form-data' \ - --form files=@index.html \ - --form googleChromeRpccBufferSize=1048576 \ - -o result.pdf -- -
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.GoogleChromeRpccBufferSize(1048576) -dest := "result.pdf" -c.Store(req, dest) -- -
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->setGoogleChromeRpccBufferSize(1048576); -$dest = 'result.pdf'; -$client->store($request, $dest); -- -
Gotenberg provides the endpoint /convert/url for remote URL conversions.
It accepts POST requests with a multipart/form-data Content-Type.
This endpoint does not accept an index.html file nor assets files but a form field
-named remoteURL instead. Otherwise, URL conversions work the same as HTML conversions.
-- -Attention: when converting a website to PDF, you should remove all margins. -If not, some of the content of the page might be hidden.
- -Attention: if you try to convert a URL from a Docker Compose service named
-app(i.e.removeURL=http://app/an/entrypoint), -the resulting PDF will be blank. Make sure to rename your service to avoid this issue.
$ curl --request POST \ - --url http://localhost:3000/convert/url \ - --header 'Content-Type: multipart/form-data' \ - --form remoteURL=https://google.com \ - --form marginTop=0 \ - --form marginBottom=0 \ - --form marginLeft=0 \ - --form marginRight=0 \ - -o result.pdf -- -
import "github.com/thecodingmachine/gotenberg-go-client/v7" - -c := &gotenberg.Client{Hostname: "http://localhost:3000"} -req := gotenberg.NewURLRequest("https://google.com") -req.Margins(gotenberg.NoMargins) -dest := "result.pdf" -c.Store(req, dest) -- -
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->setMargins(Request::NO_MARGINS); -$dest = 'result.pdf'; -$client->store($request, $dest); -- -
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-encodingisAccept-Encoding.
$ 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 -- -
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) -- -
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); -- -
Gotenberg provides the endpoint /convert/markdown for Markdown conversions.
It accepts POST requests with a multipart/form-data Content-Type.
Markdown conversions work the same as HTML conversions.
- -Only difference is that you have access to the Go template function toHTML
-in the file index.html. This function will convert a given markdown file to HTML.
For instance:
- -<!doctype html> -<html lang="en"> - <head> - <meta charset="utf-8"> - <title>My PDF</title> - </head> - <body> - {{ toHTML .DirPath "file.md" }} - </body> -</html> -- -
$ curl --request POST \ - --url http://localhost:3000/convert/markdown \ - --header 'Content-Type: multipart/form-data' \ - --form files=@index.html \ - --form files=@file.md \ - -o result.pdf -- -
import "github.com/thecodingmachine/gotenberg-go-client/v7" - -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) -- -
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', '/path/to/file'); -$markdowns = [ - DocumentFactory::makeFromPath('file.md', '/path/to/file'), -]; -$request = new MarkdownRequest($index, $markdowns); -$dest = 'result.pdf'; -$client->store($request, $dest); -- -
Gotenberg provides the endpoint /convert/office for Office document conversions.
It accepts POST requests with a multipart/form-data Content-Type.
You may send one or more Office documents. Following file extensions are accepted:
- -.txt.rtf.fodt.doc.docx.odt.xls.xlsx.ods.ppt.pptx.odpAll files will be merged into a single resulting PDF.
- --- -Attention: Gotenberg merges the PDF files alphabetically.
-
$ curl --request POST \ - --url http://localhost:3000/convert/office \ - --header 'Content-Type: multipart/form-data' \ - --form files=@document.docx \ - --form files=@document2.docx \ - -o result.pdf -- -
import "github.com/thecodingmachine/gotenberg-go-client/v7" - -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) -- -
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'), - DocumentFactory::makeFromPath('document2.docx', '/path/to/file'), -]; -$request = new OfficeRequest($files); -$dest = 'result.pdf'; -$client->store($request, $dest); -- -
You may also customize the resulting PDF format.
- -By default, it will be rendered with portrait orientation.
$ curl --request POST \ - --url http://localhost:3000/convert/office \ - --header 'Content-Type: multipart/form-data' \ - --form files=@document.docx \ - --form landscape=true \ - -o result.pdf -- -
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.Landscape(true) -dest := "result.pdf" -c.Store(req, dest) -- -
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->setLandscape(true); -$dest = 'result.pdf'; -$client->store($request, $dest); -- -
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 --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 -- -
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) -- -
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); -- -
Gotenberg provides the endpoint /merge for merging PDFs.
It accepts POST requests with a multipart/form-data Content-Type.
Nothing fancy here: you may send one or more PDF files and the API -will merge them and return the resulting PDF file.
- --- -Attention: Gotenberg merges the PDF files alphabetically.
-
$ curl --request POST \ - --url http://localhost:3000/merge \ - --header 'Content-Type: multipart/form-data' \ - --form files=@file.pdf \ - --form files=@file2.pdf \ - -o result.pdf -- -
import "github.com/thecodingmachine/gotenberg-go-client/v7" - -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) -- -
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', '/path/to/file'), - DocumentFactory::makeFromPath('file2.pdf', '/path/to/file'), -]; -$request = new MergeRequest($files); -$dest = 'result.pdf'; -$client->store($request, $dest); -- -
All endpoints accept a form field named waitTimeout.
The API will wait the given seconds before it considers the conversion to be unsucessful.
-If unsucessful, it returns a 504 HTTP code.
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 section.
-
$ curl --request POST \ - --url http://localhost:3000/convert/html \ - --header 'Content-Type: multipart/form-data' \ - --form files=@index.html \ - --form waitTimeout=2.5 -- -
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.WaitTimeout(2.5) -resp, _ := c.Post(req) -- -
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->setWaitTimeout(2.5); -$dest = 'result.pdf'; -$client->store($request, $dest); -- -
All endpoints accept a form field named webhookURL.
If provided, the API will send the resulting PDF file in a POST request with the application/pdf Content-Type
-to given URL.
By doing so, your requests to the API will be over before the conversions are actually done!
- -$ 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/' -- -
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/") -resp, _ := c.Post(req) -- -
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/'); -$resp = $client->post($request); -- -
If a webhookURL is provided, you may also send a form field named webhookURLTimeout.
The API will wait the given seconds before it considers the sending of the resulting PDF to be unsucessful.
- -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 section.
-
$ 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 -- -
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.WebhookURLTimeout(2.5) -resp, _ := c.Post(req) -- -
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->setWebhookURLTimeout(2.5); -$resp = $client->post($request); -- -
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-encodingisAccept-Encoding.
$ 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/' -- -
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) -- -
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); -- -
All endpoints accept a form field named resultFilename.
If provided, the API will return the resulting PDF file with the given filename. -Otherwise a random filename is used.
- --- -Attention: this feature does not work if the form field
-webhookURLis given.
$ curl --request POST \ - --url http://localhost:3000/convert/html \ - --header 'Content-Type: multipart/form-data' \ - --form files=@index.html \ - --form resultFilename='foo.pdf' -- -
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.ResultFilename("foo.pdf") -resp, _ := c.Post(req) -- -
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->setResultFilename('foo.pdf'); -$resp = $client->post($request); -- -
The API uses under the hood intricate programs.
- -Gotenberg tries to abstract as much complexity as possible but it can -only do it to a certain extent.
- -For instance, Office and Merge endpoints will start respectively as many LibreOffice (unoconv) and PDTk -instances as there are requests. The limitation here is the available memory and CPU usage.
- -On another hand, for the HTML, URL and Markdown endpoints, the API does only 6 conversions in parallel. -Indeed, Google Chrome misbehaves if there are too many concurrent conversions.
- -The more concurrent requests, the more 504 HTTP codes the API will return.
-- -See our load testing use case for more details about the API behaviour under heavy load.
-
You may increase the conversion timeout. In other words, you accept that a conversion takes more time -if the API is under heavy load.
- --- -See timeout section.
-
The API being stateless, you may scale it as much as you want.
- -For instance, using the following Docker Compose file:
- -version: '3' - -services: - - # your other services - - gotenberg: - image: thecodingmachine/gotenberg:6 -- -
You may now launch your services using:
- -$ docker-compose up --scale gotenberg=your_number_of_instances -- -
When requesting the Gotenberg service with your client(s), Docker will automatically -redirect a request to a Gotenberg container according to the round-robin strategy.
- -Gotenberg provides the endpoint /ping for checking the API availability with
-a simple GET request.
Currently this endpoint does nothing special. A better way to monitor -Gotenberg would be by checking the memory usage.
- -Also, as the API uses under the hood intricate programs, you should -restart your Gotenberg instances from time to time to ensure a nominal behaviour.
- -By default, a handful of fonts are installed. Asian characters are also supported out of the box.
- -If you wish to use more fonts, you will have to create your own image:
- -FROM thecodingmachine/gotenberg:6 - -USER root - -RUN apt-get -y install yourfonts - -USER gotenberg -- -
-
-
- of -
- - - - ``` - - - The following classes will allow you to inject printing values in your - document: - - - `date`: Formatted print date. - - - `title`: Document title. - - - `pageNumber`: Current page number. - - - `totalPage`: Total pages in the document. - - - There are some limitations with header and footer files: - - - JavaScript is not executed. - - - External resources are not loaded. - - - The CSS properties are independant of the ones used in the - `index.html` file. - - - `footer.html` CSS properties override the ones from `header.html`. - - - Only fonts installed in the Docker image are loaded (see the fonts - section) - - - Images only work using a `base64` encoded source, e.g. `