title: open pdf view on click of link of a html page in laravel
body: <p>PDF generated but it just downloaded, not opened in a tab.<br>
  I want to open a random generated pdf page in a browser from where the user can download it.</p>
  
  <p>I have tried pdf generating code? This is my controller.<br>
  Please suggest some code here in show function.</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use App\Item;
  use DB;
  use Excel;
  use PDF;
  use Illuminate\Http\Request;
  //use App\Mail\DemoEmail;
  use Illuminate\Support\Facades\Mail;
  
  class MaatwebsiteDemoController extends Controller
  {
  
      /**
       * Display a listing of the resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function importExport()
      {
          return view('importExport');
      }
  
      /**
       * Display a listing of the resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function downloadExcel($type)
      {
          $data = Item::get()-&gt;toArray();
  
          return Excel::create('itsolutionstuff_example', function ($excel) use ($data) {
              $excel-&gt;sheet('mySheet', function ($sheet) use ($data) {
                  $sheet-&gt;fromArray($data);
              });
          })-&gt;download($type);
      }
  
      /**
       * Display a listing of the resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function importExcel(Request $request)
      {
          $request-&gt;validate([
              'import_file' =&gt; 'required'
          ]);
  
          $path = $request-&gt;file('import_file')-&gt;getRealPath();
          $data = Excel::load($path)-&gt;get();
          //echo "&lt;pre&gt;";
          //print_r($data);exit;
  
          if ($data-&gt;count()) {
              foreach ($data as $key =&gt; $value) {
                  foreach ($value as $key1 =&gt; $x1) {
                      $arr[] = ['email' =&gt; $x1-&gt;email, 'description' =&gt; $x1-&gt;description, 'content' =&gt; $x1-&gt;content];
                  }
              }
              if (!empty($arr)) {
                  Item::insert($arr);
              }
              //$data1 = Item::get()-&gt;toArray();
              $users = Item::get()-&gt;toArray();
  
              foreach ($users as $keycc =&gt; $user) {
                  $data2[] = $user['email'];
                  Mail::send('mails.demo', $user, function ($message) use ($user) {
                      $message-&gt;to($user['email'], 'Tutorials Point')-&gt;subject('Laravel HTML Testing Mail');
                      $message-&gt;from('smitamishra1992718@gmail.com', 'Smita');
                  });
              }
  
  
              // Mail::send('emails.contact', $data, function($message) use ($data){
              // return back()-&gt;with('success', 'Insert Record successfully.');
  
          }
      }
      //Here i am loading view as pdf bt it not open in a new tab as pdf it just dowloaded.
      public function show($id)
      {
          $users = DB::select('select * from items where id = ?', [$id]);
          //view()-&gt;share('users',$users);
  
          $pdf = PDF::loadView('pdfview', array('users' =&gt; $users));
  
          return $pdf-&gt;download('demo.pdf');
      }
  
      public function downloadPDF()
  
      {
          $pdf = PDF::loadView('pdfview');
          return $pdf-&gt;download('invoice.pdf');
      }
  }
  </code></pre>
  
  <p>This is my view having a link.when we click on this link page open as pdf in browser.</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;a href="{{ route('pdfview', $id) }}"&gt;Content Detail Displayed here&lt;/a&gt;
  </code></pre>