Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Put this in top
- use DompdfDompdf;
- use DompdfOptions;
- public function DownloadPdf($id , $download = false){
- // instantiate and use the dompdf class
- $options = new Options();
- $options->set('enable_remote', true);
- $options->set('enable_css_float', true);
- $dompdf = new Dompdf($options);
- $dompdf->loadHtmlFile(action('HomeController@PdfHTML',['id'=>$id]));
- // (Optional) Setup the paper size and orientation
- $dompdf->setPaper('A4', 'portrait');
- // Render the HTML as PDF
- $dompdf->render();
- if($download == true){
- // Save PDF to server
- file_put_contents('uploads/pdf/document_'.$id.'.pdf', $dompdf->output());
- }else{
- // Output the generated PDF to Browser
- $dompdf->stream('document');
- }
- }
- public function PdfHTML($id){
- return view('home.home_pdf');
- }
- <h2>Hello world</h2>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement