title: Show on-the-fly PDF (Content-type:application/pdf) in Laravel Blade view
body: <p>I've created the DHL label creation script in Laravel and get the generated PDF, in the Controller. The "$image" is created based on the user input and supplied by DHL API as on the fly. In general (in normal PHP script, not in Laravel), we do the following to show the PDF as I see this is working fine:</p>
  
  <pre><code>header("Content-type:application/pdf");
  header("Content-Disposition:inline;filename=label_123demo.pdf");
  echo $image; 
  </code></pre>
  
  <p>So, in the controller  file, I have written the code as below:</p>
  
  <pre><code>$data['image'] = $image; // generated image from DHL API
  return view('Administrator.shipments.dhl-post', $data);
  </code></pre>
  
  <p>And in the Blade file, I wrote the following:</p>
  
  <pre><code>&lt;div style="border: 2px solid #B0AFBE; width:800px;"&gt;
  @php
  header("Content-type:application/pdf");
  header("Content-Disposition:inline;filename=label_123demo.pdf");
  echo $image; 
  @endphp
  &lt;/div&gt;
  </code></pre>
  
  <p>But it shows nothing.</p>
  
  <p>The DHL Label creation script is below:</p>
  
  <pre><code>$message_ref = '';
              for ($i=0; $i&lt; 30; $i++)
              {
                  $message_ref .= rand(0, 9);
  
              }   
              $message_time = date("Y-m-d") . "T" . date("H:i:sP");
              $ab_date = date("Y-m-d", strtotime("+1 day")); 
  
  $query =&lt;&lt;&lt;EOT
  &lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;\n
  &lt;req:ShipmentValidateRequest xmlns:req="http://www.dhl.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.dhl.com ship-val-req.xsd"&gt;\n
  &lt;Request&gt;\n
  &lt;ServiceHeader&gt;\n
  &lt;MessageTime&gt;$message_time&lt;/MessageTime&gt;\n
  &lt;MessageReference&gt;$message_ref&lt;/MessageReference&gt;\n
  &lt;SiteID&gt;XXXX&lt;/SiteID&gt;\n
  &lt;Password&gt;XXXX&lt;/Password&gt;\n
  &lt;/ServiceHeader&gt;\n
  &lt;/Request&gt;\n
  &lt;RequestedPickupTime&gt;N&lt;/RequestedPickupTime&gt;\n
  &lt;NewShipper&gt;N&lt;/NewShipper&gt;\n
  &lt;LanguageCode&gt;en&lt;/LanguageCode&gt;\n
  &lt;PiecesEnabled&gt;Y&lt;/PiecesEnabled&gt;\n
  &lt;Billing&gt;\n
  &lt;ShipperAccountNumber&gt;XXXXX&lt;/ShipperAccountNumber&gt;\n
  &lt;ShippingPaymentType&gt;S&lt;/ShippingPaymentType&gt;\n
  &lt;BillingAccountNumber&gt;XXXXX&lt;/BillingAccountNumber&gt;\n
  &lt;DutyPaymentType&gt;R&lt;/DutyPaymentType&gt;\n
  &lt;/Billing&gt;\n
  &lt;Consignee&gt;\n
  &lt;CompanyName&gt;XYZ&lt;/CompanyName&gt;\n
  &lt;AddressLine&gt;XXXXXX&lt;/AddressLine&gt;\n
  &lt;City&gt;Lekki&lt;/City&gt;\n
  &lt;Division&gt;Lagos&lt;/Division&gt;\n
  &lt;DivisionCode&gt;LG&lt;/DivisionCode&gt;\n
  &lt;PostalCode&gt;98981&lt;/PostalCode&gt;\n
  &lt;CountryCode&gt;NG&lt;/CountryCode&gt;\n
  &lt;CountryName&gt;Nigeria&lt;/CountryName&gt;\n
  &lt;Contact&gt;\n
  &lt;PersonName&gt;MyName&lt;/PersonName&gt;\n
  &lt;PhoneNumber&gt;713-530-1160&lt;/PhoneNumber&gt;\n
  &lt;PhoneExtension&gt;&lt;/PhoneExtension&gt;\n
  &lt;/Contact&gt;\n
  &lt;/Consignee&gt;\n
  &lt;Dutiable&gt;\n
  &lt;DeclaredValue&gt;200&lt;/DeclaredValue&gt;\n
  &lt;DeclaredCurrency&gt;USD&lt;/DeclaredCurrency&gt;\n
  &lt;TermsOfTrade&gt;DAP&lt;/TermsOfTrade&gt;\n
  &lt;/Dutiable&gt;\n
  &lt;Reference&gt;\n
  &lt;ReferenceID&gt;13&lt;/ReferenceID&gt;\n
  &lt;ReferenceType&gt;St&lt;/ReferenceType&gt;\n
  &lt;/Reference&gt;\n
  &lt;ShipmentDetails&gt;\n
  &lt;NumberOfPieces&gt;3&lt;/NumberOfPieces&gt;\n
  &lt;Pieces&gt;&lt;Piece&gt;\n
  &lt;PieceID&gt;3&lt;/PieceID&gt;\n
  &lt;PackageType&gt;EE&lt;/PackageType&gt;\n
  &lt;Weight&gt;8&lt;/Weight&gt;\n
  &lt;DimWeight&gt;8&lt;/DimWeight&gt;\n
  &lt;Width&gt;6&lt;/Width&gt;\n
  &lt;Height&gt;8&lt;/Height&gt;\n
  &lt;Depth&gt;8&lt;/Depth&gt;\n
  &lt;PieceContents&gt;&lt;/PieceContents&gt;\n
  &lt;/Piece&gt;&lt;/Pieces&gt;\n
  &lt;Weight&gt;287&lt;/Weight&gt;\n
  &lt;WeightUnit&gt;L&lt;/WeightUnit&gt;\n
  &lt;GlobalProductCode&gt;P&lt;/GlobalProductCode&gt;\n
  &lt;Date&gt;2018-06-27&lt;/Date&gt;\n
  &lt;Contents&gt;SHIPMENT #13&lt;/Contents&gt;\n
  &lt;DoorTo&gt;DD&lt;/DoorTo&gt;\n
  &lt;DimensionUnit&gt;I&lt;/DimensionUnit&gt;\n
  &lt;PackageType&gt;EE&lt;/PackageType&gt;\n
  &lt;IsDutiable&gt;N&lt;/IsDutiable&gt;\n
  &lt;CurrencyCode&gt;USD&lt;/CurrencyCode&gt;\n
  &lt;/ShipmentDetails&gt;\n
  &lt;Shipper&gt;\n
  &lt;ShipperID&gt;XXXXXX&lt;/ShipperID&gt;\n
  &lt;CompanyName&gt;MyCompany&lt;/CompanyName&gt;\n
  &lt;RegisteredAccount&gt;XXXXX&lt;/RegisteredAccount&gt;\n
  &lt;AddressLine&gt;Address XYX demo&lt;/AddressLine&gt;\n
  &lt;City&gt;Tuscon&lt;/City&gt;\n
  &lt;Division&gt;Iowa&lt;/Division&gt;\n
  &lt;DivisionCode&gt;IW&lt;/DivisionCode&gt;\n
  &lt;PostalCode&gt;50020&lt;/PostalCode&gt;\n
  &lt;CountryCode&gt;US&lt;/CountryCode&gt;\n
  &lt;CountryName&gt;United States&lt;/CountryName&gt;\n
  &lt;Contact&gt;\n
  &lt;PersonName&gt;PersonName&lt;/PersonName&gt;\n
  &lt;PhoneNumber&gt;12345600&lt;/PhoneNumber&gt;\n
  &lt;PhoneExtension&gt;&lt;/PhoneExtension&gt;\n
  &lt;/Contact&gt;\n
  &lt;/Shipper&gt;\n
  &lt;EProcShip&gt;N&lt;/EProcShip&gt;\n
  &lt;LabelImageFormat&gt;PDF&lt;/LabelImageFormat&gt;\n
  &lt;RequestArchiveDoc&gt;Y&lt;/RequestArchiveDoc&gt;\n
  &lt;Label&gt;\n
  &lt;LabelTemplate&gt;8X4_thermal&lt;/LabelTemplate&gt;\n
  &lt;Logo&gt;Y&lt;/Logo&gt;\n
  &lt;Resolution&gt;200&lt;/Resolution&gt;\n
  &lt;/Label&gt;\n
  &lt;/req:ShipmentValidateRequest&gt;
  EOT;
  
  $url = "https://xmlpi-ea.dhl.com/XMLShippingServlet?isUTF8Support=true";
  
          $ch = curl_init($url);
          #curl_setopt($ch, CURLOPT_MUTE, 1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
          curl_setopt($ch, CURLOPT_POST, 1);
          curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
          curl_setopt($ch, CURLOPT_POSTFIELDS, "$query");
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          $output = curl_exec($ch);
          curl_close($ch);
  preg_match("/&lt;OutputImage&gt;(.*?)&lt;\/OutputImage&gt;/", $output, $matches);
  $image = base64_decode($matches[1]);
  $data['image'] = $image;
  $data['demo'] = "demo.pdf";
  return view('Administrator.shipments.dhl-post', $data);
  </code></pre>