0

I just make a simple html page and write content to it. I created a link when I click on that link the content of the page will converted into PDF file, I have implemented this using laravel dompdf -> https://github.com/barryvdh/laravel-dompdf . Now, My problem is that all things doing good, but the PDF that is generated after click will shows that link in the PDF file. How to remove that button from PDF file. My code :

My controller : ItemController.php

class ItemController extends Controller
    {
    public function pdfview(Request $request)
    {

        if($request->has('download')){
            $pdf = \PDF::loadView('pdfview');
            return $pdf->download('pdfview.pdf');
            //return $pdf->stream();
        }

        return view('pdfview');
    }
}

My route: web.php

Route::get('/pdfview',array('as'=>'pdfview','uses'=>'ItemController@pdfview'));

My view : pdfview.blade.php

<body>
 <div class="container">
   <div class="rows"><br/>  
   <a href="{{ route('pdfview',['download'=>'pdf']) }}"> Click to PDF </a> 
      <h2 align="Center"> What is PDF ? </h2><br/><br/>
      <h4> Portable Document Format (PDF) is a file format used to present and exchange documents reliably, independent of software, hardware, or operating system.</h4>
  </div>
 </div>
</body>

Help me, If you understand my problem. Thanks

Rahul Sinha
  • 1,969
  • 14
  • 17
  • Have you tried adding a stylesheet that includes CSS to style your link text with `display: none;`? You'll want to use an appropriate media target, "dompdf" works for dompdf-only styles. – BrianS Mar 30 '17 at 23:19

1 Answers1

1

Pass a variable to the view, i.e:

$pdf = \PDF::loadView('pdfview', array('pdf' => true));
...
return view('pdfview', array('pdf' => false));

and check the variable in the template:

@if(! $pdf )
   <a href="{{ route('pdfview',['download'=>'pdf']) }}"> Click to PDF </a> 
@endif
dparoli
  • 8,891
  • 1
  • 30
  • 38
  • have you changed both lines of code in the controller? – dparoli Mar 29 '17 at 06:50
  • if you change also the last line in the controller `return view('pdfview', array('pdf' => false));` $pdf in the view should not be undefined. I tried your code with my corrections and it works, is it someting missing? – dparoli Mar 29 '17 at 08:09
  • please try to sobstitute 'pdf' => false to 'pdf' => 0 and 'pdf' => true to 'pdf' => 1 and modify the check to @if( $pdf == 0 ) – dparoli Mar 29 '17 at 08:50