首页 > 解决方案 > Laravel 将生成的 Pdf 保存在队列中

问题描述

我有一个刀片,我将 Html 转换为 pdf 并将其保存在我的本地,然后我使用实时 URL 获取 pdf 并将其保存在我的本地然后我使用 laravel 库来合并两个 pdf,它会生成通过嵌入获得单个 pdf,它之前工作得很好,现在我有一个高质量的 pdf,它需要很长时间才能合并,因此,它需要一些时间并且它返回一个最大限制内存问题,

所以我试着在队列上做

这是我的代码

 $ecg_link = 'https://storage.googleapis.com/staging.uk-production.appspot.com/test1111.pdf';
    
 $ecg_pdf = isset($ecg_link) ?  $ecg_link : '';

 if($ecg_pdf){
        $ecg_contents = file_get_contents($ecg_link);
    
        if (!File::exists(storage_path('app/public/screening/pdf'))){
            File::makeDirectory(storage_path('app/public/screening/pdf'), 0777, true, true);
        }

        \Storage::disk('public')->put('screening/pdf/'.$screening_id.'.pdf', $ecg_contents);
      
        $pdf = PDF::loadView('participants.test', 
         compact('participantdata','Allopurinol','stn_assetreview'));

        if (!File::exists(storage_path('app/public/screening/pdf/temporary-pdf'))){
            File::makeDirectory(storage_path('app/public/screening/pdf/temporary-pdf'), 0777, 
        true, true);
        }
        $pdf->save(storage_path('app/public/screening/pdf/temporary-pdf/'.$screening_id.'.pdf'));

        $pdfMerger = PDFMerger::init(); //Initialize the merger
        $pdfMerger->addPDF(storage_path('app/public/screening/pdf/temporary-pdf/'.$screening_id.'.pdf'), 'all');
        $pdfMerger->addPDF(storage_path('app/public/screening/pdf/'.$screening_id.'.pdf'), 'all' );
       

        $pdfMerger->merge();

        if (!File::exists(storage_path('app/public/screening/pdf/final-pdf'))){
            File::makeDirectory(storage_path('app/public/screening/pdf/final-pdf'), 0777, true, true);
        }
        $pdfMerger->save($screening_id.'.pdf', "download");

当我使用队列时,我无法下载excel,因为它在队列中,我有什么办法可以下载excel,否则我可以通过邮件发送这个pdf吗?

标签: javascriptphplaravellaravel-5

解决方案


您可以使用作业,并且无论何时保存数据都可以调用YourJob::dispatch()


推荐阅读