1

I would like to know if it's possible to display multiple PDF files using one route (with package Barryvdh\DomPDF). Would be something like this :

  1. User clicks on link "Download all files";
  2. Link points towards method downloadAll()
  3. This method returns multiple streams with foreach using either queues, workers or anything else that could help (each time _blank page).

My current method :

public function downloadAll(Person $person)
    {
        foreach ($person->letter as $letter) {
            dispatch(function () use ($letter) {
                return Pdf::loadView('cancellation-letter', [
                    'letter' => $letter,
                ])->stream($letter->uuid . '.pdf');
            });
        }
        return redirect()->back();
    }

Obviously this won't work, since method cannot return multiple responses. But is this possible to do in the first place? And if yes, would you have any advice on how i could do this?

StewieSWS
  • 546
  • 3
  • 10
  • 1
    There may be too many files you want downloaded. When you want to download more than one file, you cannot provide it with single request. I would solve this by making the files to be downloaded into a single zip and downloading that zip. I would do this with jobs that would render each PDF file. And i would then email a link to the zip file to the user where they can download it. – cengsemihsahin Jan 30 '23 at 10:32
  • 1
    Hello @cengsemihsahin, thank you for your advice. I thought about this as well, but the problem is that we have elderly target audience, and we're quite sure a lot of them don't even know what an archive is. :) – StewieSWS Jan 30 '23 at 10:51
  • zip all pdf then download – Mahdi Bagheri Varnosfatherani Jan 30 '23 at 12:05
  • @MahdiBagheri already stated that zip is not an option – StewieSWS Jan 30 '23 at 12:14
  • https://www.youtube.com/watch?v=IA03QeE59Fk – Mahdi Bagheri Varnosfatherani Jan 30 '23 at 12:22
  • 1
    even if it is done, browsers will stop downloading anyway if it detects that multiple files are being downloaded. chrome is especially strict about this. You might want to rethink again. – itachi Jan 31 '23 at 14:53

0 Answers0