zanysoft / laravel-zip

MIT License
300 stars 95 forks source link

convert a pdf and zip it, then download it. #33

Closed akmalseferagic closed 2 years ago

akmalseferagic commented 2 years ago

I tried to do it with this code, but I didn't know how to download it after I created the zip file.

here's my code in controller:

    //Convert data into pdf then save it to local storage 
    $apply = Form::all();
    view()->share('apply', $apply);
    $pdf = PDF::loadView('admin.pdf-apply')->setPaper('a4', 'landscape');
    Storage::put('public/pdf/data_applicant.pdf', $pdf->output());

    //Create a zip from it and download it
    $zip = Zip::create('public/storage/file.zip');
    Storage::put('public/pdf/file.zip', $zip->add('public/storage/pdf/data_applicant.pdf'));
    $zip->close();
    return response()->download($zip);
akmalseferagic commented 2 years ago

its solve with

return Storage::download('/public/pdf/add.zip');