Skip to content

Latest commit

 

History

History
94 lines (74 loc) · 1.91 KB

url-builder.md

File metadata and controls

94 lines (74 loc) · 1.91 KB

Url Builder

You may have the possibility to generate a PDF from a URL.

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

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()
        ;
    }
}

Files

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()
         ;
    }
}

Customization

Tip

For more information go to PDF customization.