Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. // Put this in top
  2. use DompdfDompdf;
  3. use DompdfOptions;
  4.  
  5. public function DownloadPdf($id , $download = false){
  6. // instantiate and use the dompdf class
  7. $options = new Options();
  8. $options->set('enable_remote', true);
  9. $options->set('enable_css_float', true);
  10. $dompdf = new Dompdf($options);
  11. $dompdf->loadHtmlFile(action('HomeController@PdfHTML',['id'=>$id]));
  12.  
  13. // (Optional) Setup the paper size and orientation
  14. $dompdf->setPaper('A4', 'portrait');
  15.  
  16. // Render the HTML as PDF
  17. $dompdf->render();
  18. if($download == true){
  19. // Save PDF to server
  20. file_put_contents('uploads/pdf/document_'.$id.'.pdf', $dompdf->output());
  21. }else{
  22. // Output the generated PDF to Browser
  23. $dompdf->stream('document');
  24. }
  25. }
  26.  
  27. public function PdfHTML($id){
  28.  
  29. return view('home.home_pdf');
  30. }
  31.  
  32. <h2>Hello world</h2>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement