Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation #49

Merged
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
655077e
Add license
StevenRenaux May 27, 2024
9d819ef
in progress
StevenRenaux May 28, 2024
f0001d5
Update README and configuration
StevenRenaux May 29, 2024
e12bf83
Add assets + router
StevenRenaux Jun 2, 2024
e7bf127
Fix README
StevenRenaux Jun 2, 2024
183cdad
Merge remote-tracking branch 'refs/remotes/origin/main' into release/…
StevenRenaux Jun 5, 2024
bcdff44
Add pdf customization + office
StevenRenaux Jun 5, 2024
b7f068b
Update assets.md
StevenRenaux Jun 5, 2024
af8a6f2
Update README.md
StevenRenaux Jun 5, 2024
a895dc7
Add screenshot customization
StevenRenaux Jun 7, 2024
1492bd6
Merge remote-tracking branch 'origin/release/Update-documentation' in…
StevenRenaux Jun 7, 2024
a3d4abb
delete file
StevenRenaux Jun 7, 2024
d9c94f0
Fix typo
StevenRenaux Jun 7, 2024
30a30cc
Update configuration doc
StevenRenaux Jun 7, 2024
c6d4cd3
Update README
StevenRenaux Jun 8, 2024
1e4f2f8
Merge remote-tracking branch 'refs/remotes/origin/main' into release/…
StevenRenaux Jun 10, 2024
6c047ef
Merge remote-tracking branch 'refs/remotes/origin/main' into release/…
StevenRenaux Jun 10, 2024
3810446
Fix reviews
StevenRenaux Jun 10, 2024
0d6aac9
Update assets
StevenRenaux Jun 14, 2024
f56c8ad
Update assets doc
StevenRenaux Jun 18, 2024
5505c88
Update assets doc
StevenRenaux Jun 18, 2024
1bae243
Update doc
StevenRenaux Jun 18, 2024
fb4786c
Update doc
StevenRenaux Jun 18, 2024
436b383
Fix path
StevenRenaux Jun 18, 2024
43b8070
Fix title size
StevenRenaux Jun 18, 2024
4380c21
Fix doc links
StevenRenaux Jun 19, 2024
d015013
Merge remote-tracking branch 'refs/remotes/origin/main' into release/…
StevenRenaux Jun 19, 2024
6932ce0
Add metadata doc
StevenRenaux Jun 19, 2024
6dbf6af
Add merge builder
StevenRenaux Jun 19, 2024
a7acfc7
typo
StevenRenaux Jun 19, 2024
ae48609
Add merge config
StevenRenaux Jun 20, 2024
4e9175d
Add default templates config
StevenRenaux Jun 20, 2024
47fde36
Fix reviews
StevenRenaux Jun 20, 2024
5b1ec41
Fix reviews
StevenRenaux Jun 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 215 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,226 @@
Gotenberg Bundle
=============================
# Gotenberg Bundle

This bundle allows you to generate, stream and save PDF locally.
## What is it ?

Documentation
-------------
This bundle allows you to generate, stream and save PDF locally from URL, HTML and Markdown.
It can convert any office file into PDF.
It also helps you to generate, stream and save screenshot locally from URL, HTML and Markdown.
Jean-Beru marked this conversation as resolved.
Show resolved Hide resolved

The entry point of the documentation can be found in the file `docs/index.rst`
## How to install

[Read the documentation](docs/index.rst)
> [!CAUTION]
> To use this bundle, you first need to install and configure [Gotenberg 8.x](https://gotenberg.dev/docs/getting-started/installation).

Credits
-------
Install the bundle using composer :

```bash
composer require sensiolabs/gotenberg-bundle
```

If not using Symfony Flex, enable the bundle by adding it to the list of
registered bundles in the ``config/bundles.php`` file of your project:

```php
// config/bundles.php

return [
// ...
SensioLabs\GotenbergBundle\SensioLabsGotenbergBundle::class => ['all' => true],
];

```

## Basic Usage

### PDF

You can generate a PDF locally from URL, HTML and Markdown.
StevenRenaux marked this conversation as resolved.
Show resolved Hide resolved

#### URL

After injecting ``GotenbergPdfInterface`` you simply need to call the method ``url``,
which will return a ``UrlPdfBuilder`` instance.

``UrlPdfBuilder`` lets you pass the URL of the page you want to convert into PDF
to the method ``url``.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;

class YourController
{
public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
{
return $gotenberg->url()
->url('https://sensiolabs.com/fr/')
->generate() // will return directly a stream response
;
}
}
```

> [!TIP]
> For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#url-into-pdf-route).

#### Twig

> [!WARNING]
> Every twig templates you pass to Gotenberg need to have the following structure.
> Even Header or Footer parts.
> ```html
> <!DOCTYPE html>
> <html lang="en">
> <head>
> <meta charset="utf-8" />
> <title>My PDF</title>
> </head>
> <body>
> <!-- Your code goes here -->
> </body>
> </html>
> ```

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;

class YourController
{
public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
{
return $gotenberg->html()
->content('twig_simple_pdf.html.twig', [
'my_var' => 'value'
])
->generate() // will return directly a stream response
;
}
}
```

If a template needs to link to a static asset (e.g. an image), this bundle provides a `{{ gotenberg_asset() }}`
Twig function to generate the correct path AND add it to the builder automatically.

This function work as [asset() Twig function](https://symfony.com/doc/current/templates.html#linking-to-css-javascript-and-image-assets)
and fetch your assets in the `assets` folder of your application
If your files are in another folder, you can override the default value of ``assets_directory`` in your
configuration file ``config/sensiolabs_gotenberg.yml``.
The path provided can be relative as well as absolute.

```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>PDF body</title>
</head>
<body>
<main>
<h1>Hello world!</h1>
<img src="{{ gotenberg_asset('public/img/ceo.jpeg') }}" alt="CEO"/>
<img src="{{ gotenberg_asset('public/img/admin.jpeg') }}" alt="Admin"/>
</main>
</body>
</html>
```

> [!TIP]
> For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#html-file-into-pdf-route).

### Screenshot

You can generate a screenshot locally from URL, HTML and Markdown.

#### URL

After injecting ``GotenbergScreenshotInterface`` you simply need to call the method ``url``,
which will return a ``UrlScreenshotBuilder`` instance.

``UrlScreenshotBuilder`` lets you pass the URL of the page you want to convert into screenshot
to the method ``url``.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\GotenbergScreenshotInterface;

class YourController
{
public function yourControllerMethod(GotenbergScreenshotInterface $gotenberg): Response
{
return $gotenberg->url()
->url('https://sensiolabs.com/fr/')
->generate()
;
}
}
```
#### Twig

After injecting ``GotenbergScreenshotInterface`` you simply need to call the method ``html``,
which will return a ``HtmlScreenshotBuilder`` instance.

``HtmlScreenshotBuilder`` lets you pass the content of the page you want to convert into screenshot
to the method ``content``.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\GotenbergScreenshotInterface;

class YourController
{
public function yourControllerMethod(GotenbergScreenshotInterface $gotenberg): Response
{
return $gotenberg->html()
->content('twig_simple_pdf.html.twig', [
'my_var' => 'value'
])
->generate()
;
}
}
```

> [!TIP]
> For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#screenshots-route).

### Advanced Usage
StevenRenaux marked this conversation as resolved.
Show resolved Hide resolved

1. [Configuration](docs/configuration.md)
2. [Working with assets](docs/assets.md)
3. [Router integration](docs/router.md)
4. [Add header / footer](docs/header-footer.md) (available for PDF and every builder except LibreOffice)
5. [Convert office file and customization](docs/office.md) (available extensions for conversion below)

`123`, `602`, `abw`, `bib`, `bmp`, `cdr`, `cgm`, `cmx`, `csv`, `cwk`, `dbf`, `dif`, `doc`, `docm`,
`docx`, `dot`, `dotm`, `dotx`, `dxf`, `emf`, `eps`, `epub`, `fodg`, `fodp`, `fods`, `fodt`, `fopd`,
`gif`, `htm`, `html`, `hwp`, `jpeg`, `jpg`, `key`, `ltx`, `lwp`, `mcw`, `met`, `mml`, `mw`, `numbers`,
`odd`, `odg`, `odm`, `odp`, `ods`, `odt`, `otg`, `oth`, `otp`, `ots`, `ott`, `pages`, `pbm`, `pcd`,
`pct`, `pcx`, `pdb`, `pdf`, `pgm`, `png`, `pot`, `potm`, `potx`, `ppm`, `pps`, `ppt`, `pptm`, `pptx`,
`psd`, `psw`, `pub`, `pwp`, `pxl`, `ras`, `rtf`, `sda`, `sdc`, `sdd`, `sdp`, `sdw`, `sgl`, `slk`,
`smf`, `stc`, `std`, `sti`, `stw`, `svg`, `svm`, `swf`, `sxc`, `sxd`, `sxg`, `sxi`, `sxm`, `sxw`,
`tga`, `tif`, `tiff`, `txt`, `uof`, `uop`, `uos`, `uot`, `vdx`, `vor`, `vsd`, `vsdm`, `vsdx`, `wb2`,
`wk1`, `wks`, `wmf`, `wpd`, `wpg`, `wps`, `xbm`, `xhtml`, `xls`, `xlsb`, `xlsm`, `xlsx`, `xlt`, `xltm`,
`xltx`, `xlw`, `xml`, `xpm`, `zabw`
Jean-Beru marked this conversation as resolved.
Show resolved Hide resolved
6. [PDF customization](docs/pdf-customization.md) (available for every builder except LibreOffice)
7. [Screenshot customization](docs/screenshot-customization.md)

### Profiler

Comes with a built-in profiler panel to help you during your development.

## Credits

This bundle was inspired by [Gotenberg PHP](https://github.com/gotenberg/gotenberg-php).
- [Steven RENAUX](https://github.com/StevenRenaux)
- [Adrien ROCHES](https://github.com/Neirda24)
- [All Contributors](../../contributors)

Licence
-------
## Licence

MIT License (MIT): see the [License File](LICENSE) for more details.

Loading