Download the PHP package gotenberg/gotenberg-php without Composer

On this page you can find all versions of the php package gotenberg/gotenberg-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package gotenberg-php

Gotenberg PHP Logo

Gotenberg PHP

A PHP client for interacting with Gotenberg

Latest Version Total Downloads Continuous Integration https://codecov.io/gh/gotenberg/gotenberg


This package is a PHP client for Gotenberg, a developer-friendly API to interact with powerful tools like Chromium and LibreOffice for converting numerous document formats (HTML, Markdown, Word, Excel, etc.) into PDF files, and more!

⚠️

For Gotenberg 6.x, use thecodingmachine/gotenberg-php-client instead.

For Gotenberg 7.x, use version v1.1.8.

Quick Examples

You may convert a target URL to PDF and save it to a given directory:

You may also convert Office documents and merge them:

Requirement

This packages requires Gotenberg, a Docker-powered stateless API for PDF files.

See the installation guide for more information.

Installation

This package can be installed with Composer:

We use PSR-7 HTTP message interfaces (i.e., RequestInterface and ResponseInterface) and the PSR-18 HTTP client interface (i.e., ClientInterface).

For the latter, you may need an adapter in order to use your favorite client library. Check the available adapters:

If you're not sure which adapter you should use, consider using the php-http/guzzle7-adapter:

Usage

Send a request to the API

After having created the HTTP request (see below), you have two options:

  1. Get the response from the API and handle it according to your need.
  2. Save the resulting file to a given directory.

In the following examples, we assume the Gotenberg API is available at http://localhost:3000.

Get a response

You may use any HTTP client that is able to handle a PSR-7 RequestInterface to call the API:

If you have a PSR-18 compatible HTTP client (see Installation), you may also use Gotenberg::send:

This helper will parse the response and if it is not 2xx, it will throw an exception. That's especially useful if you wish to return the response directly to the browser.

You may also explicitly set the HTTP client:

Save the resulting file

If you have a PSR-18 compatible HTTP client (see Installation), you may use Gotenberg::save:

It returns the filename of the resulting file. By default, Gotenberg creates a UUID filename (i.e., 95cd9945-484f-4f89-8bdb-23dbdd0bdea9) with either a .zip or a .pdf file extension.

You may also explicitly set the HTTP client:

Filename

You may override the output filename with:

Gotenberg will automatically add the correct file extension.

Trace or request ID

By default, Gotenberg creates a UUID trace that identifies a request in its logs. You may override its value thanks to:

It will set the header Gotenberg-Trace with your value. You may also override the default header name:

Please note that it should be the same value as defined by the --api-trace-header Gotenberg's property.

The response from Gotenberg will also contain the trace header. In case of error, both the Gotenberg::send and Gotenberg::save methods throw a GotenbergApiErroed exception that provides the following method for retrieving the trace:

Chromium

The Chromium module interacts with the Chromium browser to convert HTML documents to PDF or capture screenshots.

Convert a target URL to PDF

See https://gotenberg.dev/docs/routes#url-into-pdf-route.

Converting a target URL to PDF is as simple as:

Convert an HTML document to PDF

See https://gotenberg.dev/docs/routes#html-file-into-pdf-route.

You may convert an HTML document with:

Or with an HTML string:

Please note that it automatically sets the filename to index.html, as required by Gotenberg, whatever the value you're using with the Stream class.

You may also send additional files, like images, fonts, stylesheets, and so on. The only requirement is that their paths in the HTML DOM are on the root level.

Convert one or more markdown files to PDF

See https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route.

You may convert markdown files with:

The first argument is a Stream with HTML content, for instance:

Here, there is a Go template function toHTML. Gotenberg will use it to convert a markdown file's content to HTML.

Like the HTML conversion, you may also send additional files, like images, fonts, stylesheets, and so on. The only requirement is that their paths in the HTML DOM are on the root level.

Single page

You may print the entire content in one single page with:

Paper size

You may override the default paper size with:

Examples of paper size (width x height, in inches):

Margins

You may override the default margins (i.e., 0.39, in inches):

Prefer CSS page size

You may force page size as defined by CSS:

Print the background graphics

You may also hide the default white background and allow generating PDFs with transparency with:

The rules regarding the printBackground and omitBackground form fields are the following:

Landscape orientation

You may override the default portrait orientation with:

Scale

You may override the default scale of the page rendering (i.e., 1.0) with:

Page ranges

You may set the page ranges to print, e.g., 1-5, 8, 11-13. Empty means all pages.

Header and footer

You may add a header and/or a footer to each page of the PDF:

Please note that it automatically sets the filenames to header.html and footer.html, as required by Gotenberg, whatever the value you're using with the Stream class.

Wait delay

When the page relies on JavaScript for rendering, and you don't have access to the page's code, you may want to wait a certain amount of time (i.e., 1s, 2ms, etc.) to make sure Chromium has fully rendered the page you're trying to generate.

Wait for expression

You may also wait until a given JavaScript expression returns true:

Emulate media type

Some websites have dedicated CSS rules for print. Using screen allows you to force the "standard" CSS rules:

You may also force the print media type with:

Extra HTTP headers

You may add HTTP headers that Chromium will send when loading the HTML document:

Invalid HTTP status codes

You may force Gotenberg to return a 409 Conflict response if the HTTP status code from the main page is not acceptable:

A X99 entry means every HTTP status codes between X00 and X99 (e.g., 499 means every HTTP status codes between 400 and 499).

Fail on console exceptions

You may force Gotenberg to return a 409 Conflict response if there are exceptions in the Chromium console:

Performance mode

Gotenberg, by default, waits for the network idle event to ensure that the majority of the page is rendered during conversion. However, this often significantly slows down the conversion process. Setting skipNetworkEventIdle form field to true can greatly enhance the conversion speed.

PDF/A & PDF/UA

See https://gotenberg.dev/docs/routes#pdfa-chromium.

You may set the PDF/A format and enable PDF/UA for the resulting PDF with:

Screenshots

You can capture full-page screenshots using the following three routes, which function similarly to their PDF equivalents:

LibreOffice

The LibreOffice module interacts with LibreOffice to convert documents to PDF, thanks to unoconv.

Convert documents to PDF

See https://gotenberg.dev/docs/routes#office-documents-into-pdfs-route.

Converting a document to PDF is as simple as:

If you send many documents, Gotenberg will return a ZIP archive with the PDFs:

You may also merge them into one unique PDF:

Please note that the merging order is determined by the order of the arguments.

Landscape orientation

You may override the default portrait orientation with:

Page ranges

You may set the page ranges to print, e.g., 1-4. Empty means all pages.

⚠️ The page ranges are applied to all files independently.

PDF/A & PDF/UA

See https://gotenberg.dev/docs/routes#pdfa-libreoffice.

You may set the PDF/A format and enable PDF/UA for the resulting PDF(s) with:

PDF Engines

The PDF Engines module gathers all engines that can manipulate PDF files.

Merge PDFs

See https://gotenberg.dev/docs/routes#merge-pdfs-route.

Merging PDFs is as simple as:

Please note that the merging order is determined by the order of the arguments.

You may also set the PDF/A format and enable PDF/UA for the resulting PDF with:

Convert to a specific PDF format

See https://gotenberg.dev/docs/routes#convert-into-pdfa-route.

You may convert a PDF to a specific PDF/A format and enable PDF/UA with:

If you send many PDFs, Gotenberg will return a ZIP archive with the PDFs:

Webhook

The Webhook module is a Gotenberg middleware that sends the API responses to callbacks.

⚠️ You cannot use the Gotenberg::save method if you're using the webhook feature.

For instance:

You may also override the default HTTP method (POST) that Gotenberg will use to call the webhooks:

You may also tell Gotenberg to add extra HTTP headers that it will send alongside the request to the webhooks:


All versions of gotenberg-php with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1|^8.2|^8.3
ext-json Version *
ext-mbstring Version *
guzzlehttp/psr7 Version ^1 || ^2.1
php-http/discovery Version ^1.14
psr/http-client Version ^1.0
psr/http-message Version ^1.0|^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package gotenberg/gotenberg-php contains the following files

Loading the files please wait ....