Convertise Data in Pdf in laravel 5.3

筅森魡賤 提交于 2019-12-25 19:15:38

问题


I want to convert data in pdf using laravel 5.3. I have tried using fpdf. but i did not get any success. how to convert data in pdf using laravel 5.3.


回答1:


This is the code which which I used in my ReportsController and will help you to convert your data into pdf

public function getDownloadPDF($id){

        $objReports=Walkthrough::find($id);
        $objReports=DB::table('walkthroughs')
                    ->join('users','users.id','=','walkthroughs.user_id')
                    ->select('users.first_name as FirstName','users.last_name as LastName','walkthroughs.start_date as StartDate','walkthroughs.end_date as EndDate','walkthroughs.unit as Unit','walkthroughs.reminder_date as ReminderDate','walkthroughs.address')
                    ->where('walkthroughs.id','=',$id)
                    ->first();

         $view = \View::make('pdf.admin_reports',
         compact('objReports'))->render(); 

        $pdf = \App::make('dompdf.wrapper');
        $pdf->loadHTML($view);
        $pdf_name = date('YmdHis').$id. '.pdf';
        $pdf->save(public_path('assets/pdf/' . $pdf_name));

         return Redirect::to('/assets/pdf/'.$pdf_name);
}

So similarly you can take data from database and convert it to pdf. Also use following code to render your view

$view = \View::make('pdf.walkthroughDetail',
                            compact('walkthrough','completed_time','selectedRoomTags',
                            'items','selectedTags','housemates','landlords',
                            'inspector_info','completed_time'))->render(); 

        $pdf = \App::make('dompdf.wrapper');
        $pdf->loadHTML($view);
        $pdf_name = date('Ymdhis') . '.pdf';
        $pdf->save(public_path('assets/pdf/' . $pdf_name));

In this case your view pdf.walkthroughDetail is converted into pdf file.



来源:https://stackoverflow.com/questions/39343361/convertise-data-in-pdf-in-laravel-5-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!