Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic PDF support #80

Open
pxlrbt opened this issue May 30, 2023 · 6 comments
Open

Basic PDF support #80

pxlrbt opened this issue May 30, 2023 · 6 comments

Comments

@pxlrbt
Copy link
Owner

pxlrbt commented May 30, 2023

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);
        });
    }
@jimiero
Copy link

jimiero commented Feb 21, 2025

@pxlrbt i'm using this on my resource table

->headerActions([
                ExportAction::make('pdf')
                    ->label('PDF')
                    ->color('gray')
                    ->exports([
                        ExcelExport::make()->withWriterType(\Maatwebsite\Excel\Excel::TCPDF)->label('PDF')->fromTable()->withFilename('my-resource.pdf'),
                    ])
            ])

how can i change that to provide the pdf orientation when it exports to pdf my table?

@pxlrbt
Copy link
Owner Author

pxlrbt commented Feb 21, 2025

Did you try the approach mentioned above?
I never exported to PDF via Maatswebsite\Excel package, so I can't tell more.

@jimiero
Copy link

jimiero commented Feb 21, 2025

I don't know where exactly to use the code above, and I'm not using a custom export as you see my action above

@pxlrbt
Copy link
Owner Author

pxlrbt commented Feb 21, 2025

Either to a ServiceProvider (first example) or your page class (third example)

@jimiero
Copy link

jimiero commented Feb 21, 2025

thanks, works using ServiceProvider, but now i have another issues 🤦 the table column widths get too big and the pdf doesn't look fine.. any idea if I can shrink those inside the pdf?

@pxlrbt
Copy link
Owner Author

pxlrbt commented Feb 21, 2025

Sorry, as I said, I never used the PDF export before, so I can't really help with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants