barryvdh / laravel-snappy

Laravel Snappy PDF
MIT License
2.63k stars 290 forks source link

How to download in batches #446

Closed WangQuanTang closed 2 years ago

WangQuanTang commented 3 years ago

Hi!There are some data like this:

$data = [
            "v0001" => [
                ["name" => "v0001", "city" => "shanghai"],
                ["name" => "v0001", "city" => "beijing"]
            ],
            "v0002" => [
                ["name" => "v0002", "city" => "shanghai"],
                ["name" => "v0002", "city" => "beijing"]
            ],
            "v0003" => [
                ["name" => "v0003", "city" => "shanghai"],
                ["name" => "v0003", "city" => "beijing"]
            ],
            "v0004" => [
                ["name" => "v0004", "city" => "shanghai"],
                ["name" => "v0004", "city" => "beijing"]
            ],
        ];

I want to export every array elements to PDF separately.And I tyied to use foreach like this:

foreach ($data as $key => $logs){
            $pdf = PDF::loadView('admin.test', compact('logs'))->setPaper('a4')->setOrientation('landscape');
            return $pdf->download($key.'.pdf');
        }

But,you konw,We can't use return in foreach.Because 'return' will cause the loop to exit!And When I remove the return, the page is blank!Could you tell me how to download in batches,please?Thank you!(My english is poor.I used Google Translate to translate my question )

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/KnpLabs/snappy instead. When having doubts, please try to reproduce the issue with just snappy. If you believe this is an actual issue with the latest version of laravel-snappy, please reply to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.