# Shopware 6 generate Pdf

**URL:** https://forum.shopware.com/t/shopware-6-generate-pdf/100200
**Category:** Administration (EN)
**Tags:** administration
**Created:** [22. Juni 2023 um 03:45 UTC](https://forum.shopware.com/t/shopware-6-generate-pdf/100200 "2023-06-22T03:45:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![chenalcones](https://avatars.discourse-cdn.com/v4/letter/c/f0a364/32.png) [@chenalcones](https://forum.shopware.com/u/chenalcones)
#### Post date: [22. Juni 2023 um 03:45 UTC](https://forum.shopware.com/t/shopware-6-generate-pdf/100200/1 "2023-06-22T03:45:44Z")

</div>

I’ve created an action button in admin product section. And when it’s clicked I want to generate or download a pdf file. I don’t know how to use the shopware 6 built-in pdf renderer. Can anyone help me? Or is there a documentation for this?

---

<div class="post-metadata">

### Author: ![chamaw](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@chamaw](https://forum.shopware.com/u/chamaw)
#### Post date: [22. Juni 2023 um 04:54 UTC](https://forum.shopware.com/t/shopware-6-generate-pdf/100200/2 "2023-06-22T04:54:58Z")

</div>

hi,  
please a small piece of code below. Of cause you can also use twig to generate the content

```auto
use Dompdf\Dompdf;
use Dompdf\Options;

public function generatePdf($htmlContent, $mode = 'return', $filename = 'output.pdf') {
        $options = new Options();
        $options->set('defaultFont', 'Helvetica');
        $options->set('isRemoteEnabled', true);
        
        $dompdf = new Dompdf($options);
        $a4 = [0, 0, 595.28, 841.89];
        // $a4 = 'a4';
        $dompdf->setPaper($a4, 'portrait');
        
        $dompdf->loadHtml($htmlContent);
        $dompdf->render();
        
        if ($mode == 'return') {
            return $dompdf->output();
        } elseif (($mode == 'echo') or ($mode == 'stream')) {
            $dompdf->stream($filename, ['Attachment' => true, 'compress' => true]);
        } elseif ($mode == 'save') {
            file_put_contents($filename, $dompdf->output());
        }
        return true;
    }

```
