在Laravel 5.3中以Pdf格式转换数据 [英] Convertise Data in Pdf in laravel 5.3

查看:111
本文介绍了在Laravel 5.3中以Pdf格式转换数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用laravel 5.3将数据转换为pdf.我试过使用fpdf.但我没有取得任何成功.如何使用laravel 5.3转换pdf中的数据.

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.

推荐答案

这是我在ReportsController中使用的代码,它将帮助您将数据转换为pdf

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);
}

因此,类似地,您可以从数据库中获取数据并将其转换为pdf. 还可以使用以下代码来呈现您的视图

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));

在这种情况下,您的视图pdf.walkthroughDetail将转换为pdf文件.

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

这篇关于在Laravel 5.3中以Pdf格式转换数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆