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.
Download gotenberg/gotenberg-php
More information about gotenberg/gotenberg-php
Files in gotenberg/gotenberg-php
Package gotenberg-php
Short Description A PHP client for interacting with Gotenberg, a developer-friendly API for converting numerous document formats into PDF files, and more!
License MIT
Homepage https://github.com/gotenberg/gotenberg-php
Informations about the package gotenberg-php
Gotenberg PHP
A PHP client for interacting with 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!
Gotenberg version | Client |
---|---|
8.x (current) |
v2.x (current) |
7.x |
v1.x |
6.x |
thecodingmachine/gotenberg-php-client |
Quick Examples
You may convert a target URL to PDF and save it to a given directory:
You may also convert Office documents:
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
:
Build a request
This package is organized around modules, namely:
Each of these modules offers a variety of methods to populate a multipart/form-data request.
After setting all optional form fields and files, you can create a request by calling the method that represents the endpoint.
For example, to call the /forms/chromium/convert/url
route:
[!TIP] Head to the documentation to learn about all possibilities.
If the route requires form files, use the Stream
class to create them:
Send a request to the API
After having created the HTTP request, you have two options:
- Get the response from the API and handle it according to your need.
- Save the resulting file to a given directory.
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:
All versions of gotenberg-php with dependencies
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