You may have the possibility to generate a PDF from a URL.
URL of the page you want to convert into PDF.
namespace App\Controller;
use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;
class YourController
{
public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
{
return $gotenberg->url()
->url('https://sensiolabs.com/fr/')
->generate()
->stream()
;
}
}
Route of the page you want to convert into PDF.
Warning
You must provide a URL accessible by Gotenberg with a public Host.
Or configure sensiolabs_gotenberg.yaml
# config/packages/sensiolabs_gotenberg.yaml
sensiolabs_gotenberg:
request_context:
base_uri: 'http://host.docker.internal:3000'
namespace App\Controller;
use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;
class YourController
{
public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
{
return $gotenberg->url()
->route('home', [
'my_var' => 'value'
])
->generate()
->stream()
;
}
}
Required to generate a PDF from Markdown builder. You can pass several files with that method.
namespace App\Controller;
use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;
class YourController
{
public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
{
return $gotenberg->markdown()
->wrapper('wrapper.html.twig', [
'my_var' => 'value'
])
->files(
'header.md',
'content.md',
'footer.md',
)
->generate()
->stream()
;
}
}
Tip
For more information go to PDF customization.