pxlrbt / filament-excel

Excel Export for Filament Admin Resources
MIT License
355 stars 68 forks source link

Basic PDF support #80

Open pxlrbt opened 1 year ago

pxlrbt commented 1 year ago

From Discord:

Hi Dennis, I hope you're doing well. I just wanted to let you know that I was able to landscape the PDF using the event as you suggested. Thank you for your help! Here are the code I have used:

Sheet::listen(BeforeSheet::class, function ($sheet) {
            $sheet->getDelegate()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE);

            $sheet->getDelegate()->getStyle('1')->getFont()->setSize(8);
        });

However, you can use the RegistersEventListeners trait to automatically register the event listeners. To do so, simply add the trait to your class and include this function within your class: beforeSheet(BeforeSheet $event) { $event->sheet->getDelegate()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE); }

or you can just add this one in your Page without trait

public function boot()
    {
        Sheet::listen(BeforeSheet::class, function ($sheet) {
            $sheet->getDelegate()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE);

            $sheet->getDelegate()->getStyle('1')->getFont()->setSize(8);
        });
    }