1. Go to this page and download the library: Download gotenberg/gotenberg-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
gotenberg / gotenberg-php example snippets
use Gotenberg\Gotenberg;
// Converts a target URL to PDF and saves it to a given directory.
$filename = Gotenberg::save(
Gotenberg::chromium($apiUrl)->pdf()->url('https://my.url'),
$pathToSavingDirectory
);
use Gotenberg\Gotenberg;
use Gotenberg\Stream;
// Converts Office documents to PDF.
$response = Gotenberg::send(
Gotenberg::libreOffice($apiUrl)
->convert(
Stream::path($pathToDocx),
Stream::path($pathToXlsx)
)
);
use Gotenberg\Gotenberg;
Gotenberg::chromium($apiUrl);
Gotenberg::libreOffice($apiUrl);
Gotenberg::pdfEngines($apiUrl);
use Gotenberg\Gotenberg;
Gotenberg::chromium($apiUrl)
->pdf() // Or screenshot().
->singlePage() // Optional.
->url('https://my.url'));
use Gotenberg\DownloadFrom;
use Gotenberg\Gotenberg;
use Gotenberg\Stream;
Gotenberg::libreOffice($apiUrl)
->convert(Stream::path($pathToDocument));
// Alternatively, you may also set the content directly.
Gotenberg::chromium($apiUrl)
->pdf()
->assets(Stream::string('style.css', 'body{font-family: Arial, Helvetica, sans-serif;}'))
->html(Stream::string('index.html', '<html><head><link rel="stylesheet" type="text/css" href="style.css"></head><body><p>Hello, world!</p></body></html>'));
// Or create your stream from scratch.
Gotenberg::libreOffice($apiUrl)
->convert(new Stream('document.docx', $stream));
// Or even tell Gotenberg to download the files for you.
Gotenberg::libreOffice($apiUrl)
->downloadFrom([
new DownloadFrom('https://url.to.document.docx', ['MyHeader' => 'MyValue'])
])
->convert();
use Gotenberg\Gotenberg;
$request = Gotenberg::chromium($apiUrl)
->pdf()
->url('https://my.url');
$response = $client->sendRequest($request);