title: Error: Using $this when not in object context - generate pdf using dompdf laravel
body: <p>I wanted to generate <code>pdf</code> of the <code>view</code> file <code>certificate_template</code> &amp; store the generated pdf file in <code>public</code> with the filename <code>certificate.pdf</code> . Below is what i tried.I got stuck with the below errors too. Any help is much appreciated.</p>
  <pre><code>use Barryvdh\DomPDF\PDF;
  return PDF::loadView('certificate_template', $data)-&gt;stream();
  //$file='certificate.pdf';
  </code></pre>
  <p>I've installed <code>dompdf</code> with <code>composer require barryvdh/laravel-dompdf</code>.</p>
  <p>added the correct <code>providers</code> &amp; <code>aliases</code> in <code>config\app.php</code>.</p>
  <p>The above code gives me the error</p>
  <blockquote>
  <p>Error: Using $this when not in object context in file C:\wamp\abc\vendor\barryvdh\laravel-dompdf\src\PDF.php on line 133</p>
  </blockquote>
  <p>so i tried the below code, then i get the error</p>
  <blockquote>
  <p>ArgumentCountError: Too few arguments to function Barryvdh\DomPDF\PDF::__construct(), 0 passed in C:\wamp\www\abc\app\Http\Controllers\CertificatesController.php on line 415 and exactly 4 expected in file C:\wamp\www\abc\vendor\barryvdh\laravel-dompdf\src\PDF.php on line 49</p>
  </blockquote>
  <pre><code>$pdf=new PDF;
  return $pdf-&gt;loadView('certificate_template', $data);
  </code></pre>
  <p><strong>EDIT</strong></p>
  <p>The below code saves pdf file but its in binary format. I wanted it to be storedin original format.How can i do that?</p>
  <pre><code>$pdf=app()-&gt;make(PDF::class); 
  $pdf-&gt;loadView('certificate_template', $data); 
  $pdf-&gt;save('certificate_template.pdf');
  return $pdf;
  </code></pre>