Skip to content

Latest commit

 

History

History
91 lines (71 loc) · 2.02 KB

url-builder.md

File metadata and controls

91 lines (71 loc) · 2.02 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()
             ;
        }
    }

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

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

Customization

Tip

For more information go to PDF customization.