2016-09-06 53 views
-1

我想使用laravel 5.3轉換pdf中的數據。我曾嘗試使用fpdf。但我沒有得到任何成功。如何使用laravel 5.3轉換PDF格式的數據。laravel 5.3在pdf中的公開數據5.3

+0

增加了一些代碼。你的嘗試。 「我沒有獲得任何成功」意味着有任何錯誤? – vijaykumar

回答

0

這是我在ReportsController使用這其中,並會幫助您將數據轉換成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格式的代碼。 還可以使用下面的代碼來渲染視圖

$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文件。

+0

我想使用laravel 5.3轉換pdf表格的記錄。如何使用上面提到的代碼在controller.shall我檢索數據在視圖中。以及如何在controller.do中調用我需要下載任何文件轉換數據pdf –

+0

檢查視圖渲染代碼,我編輯答案。你只需要寫你的觀點,以便你想看到你的PDF,因爲最後你的觀點將轉換成PDF。 – Nil

+0

如果您在這裏遇到任何問題,請告知我。 – Nil