0
votes

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

1
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

1 Answers

1
votes

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