Skip to content

Latest commit

 

History

History
73 lines (58 loc) · 1.69 KB

html-builder.md

File metadata and controls

73 lines (58 loc) · 1.69 KB

HTML Builder

You may have the possibility to convert HTML or Twig files into PDF.

Warning

Every HTML or Twig template you pass to Gotenberg need to have the following structure.
Even Header or Footer parts.

       <!DOCTYPE html>
       <html lang="en">
         <head>
           <meta charset="utf-8" />
           <title>My PDF</title>
         </head>
         <body>
           <!-- Your code goes here -->
         </body>
       </html>

HTML content

The HTML file to convert into PDF.

Warning

As assets files, by default the HTML files are fetch in the assets folder of your application.
For more information about path resolution go to assets documentation.

    namespace App\Controller;

    use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;

    class YourController
    {
        public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
        {
            return $gotenberg->html()
                ->contentFile('../templates/content.html')
                ->generate()
             ;
        }
    }

Twig content

The Twig file to convert into PDF.

    namespace App\Controller;

    use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;

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

Customization

Tip

For more information go to PDF customization.