Q:

Show on-the-fly PDF (Content-type:application/pdf) in Laravel Blade view

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:
header("Content-type:application/pdf");
header("Content-Disposition:inline;filename=label_123demo.pdf");
echo $image; 

So, in the controller  file, I have written the code as below:
$data['image'] = $image; // generated image from DHL API
return view('Administrator.shipments.dhl-post', $data);

And in the Blade file, I wrote the following:
<div style="border: 2px solid #B0AFBE; width:800px;">
@php
header("Content-type:application/pdf");
header("Content-Disposition:inline;filename=label_123demo.pdf");
echo $image; 
@endphp
</div>

But it shows nothing.
The DHL Label creation script is below:
$message_ref = '';
            for ($i=0; $i< 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 =<<<EOT
<?xml version="1.0" encoding="ISO-8859-1"?>\n
<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">\n
<Request>\n
<ServiceHeader>\n
<MessageTime>$message_time</MessageTime>\n
<MessageReference>$message_ref</MessageReference>\n
<SiteID>XXXX</SiteID>\n
<Password>XXXX</Password>\n
</ServiceHeader>\n
</Request>\n
<RequestedPickupTime>N</RequestedPickupTime>\n
<NewShipper>N</NewShipper>\n
<LanguageCode>en</LanguageCode>\n
<PiecesEnabled>Y</PiecesEnabled>\n
<Billing>\n
<ShipperAccountNumber>XXXXX</ShipperAccountNumber>\n
<ShippingPaymentType>S</ShippingPaymentType>\n
<BillingAccountNumber>XXXXX</BillingAccountNumber>\n
<DutyPaymentType>R</DutyPaymentType>\n
</Billing>\n
<Consignee>\n
<CompanyName>XYZ</CompanyName>\n
<AddressLine>XXXXXX</AddressLine>\n
<City>Lekki</City>\n
<Division>Lagos</Division>\n
<DivisionCode>LG</DivisionCode>\n
<PostalCode>98981</PostalCode>\n
<CountryCode>NG</CountryCode>\n
<CountryName>Nigeria</CountryName>\n
<Contact>\n
<PersonName>MyName</PersonName>\n
<PhoneNumber>713-530-1160</PhoneNumber>\n
<PhoneExtension></PhoneExtension>\n
</Contact>\n
</Consignee>\n
<Dutiable>\n
<DeclaredValue>200</DeclaredValue>\n
<DeclaredCurrency>USD</DeclaredCurrency>\n
<TermsOfTrade>DAP</TermsOfTrade>\n
</Dutiable>\n
<Reference>\n
<ReferenceID>13</ReferenceID>\n
<ReferenceType>St</ReferenceType>\n
</Reference>\n
<ShipmentDetails>\n
<NumberOfPieces>3</NumberOfPieces>\n
<Pieces><Piece>\n
<PieceID>3</PieceID>\n
<PackageType>EE</PackageType>\n
<Weight>8</Weight>\n
<DimWeight>8</DimWeight>\n
<Width>6</Width>\n
<Height>8</Height>\n
<Depth>8</Depth>\n
<PieceContents></PieceContents>\n
</Piece></Pieces>\n
<Weight>287</Weight>\n
<WeightUnit>L</WeightUnit>\n
<GlobalProductCode>P</GlobalProductCode>\n
<Date>2018-06-27</Date>\n
<Contents>SHIPMENT #13</Contents>\n
<DoorTo>DD</DoorTo>\n
<DimensionUnit>I</DimensionUnit>\n
<PackageType>EE</PackageType>\n
<IsDutiable>N</IsDutiable>\n
<CurrencyCode>USD</CurrencyCode>\n
</ShipmentDetails>\n
<Shipper>\n
<ShipperID>XXXXXX</ShipperID>\n
<CompanyName>MyCompany</CompanyName>\n
<RegisteredAccount>XXXXX</RegisteredAccount>\n
<AddressLine>Address XYX demo</AddressLine>\n
<City>Tuscon</City>\n
<Division>Iowa</Division>\n
<DivisionCode>IW</DivisionCode>\n
<PostalCode>50020</PostalCode>\n
<CountryCode>US</CountryCode>\n
<CountryName>United States</CountryName>\n
<Contact>\n
<PersonName>PersonName</PersonName>\n
<PhoneNumber>12345600</PhoneNumber>\n
<PhoneExtension></PhoneExtension>\n
</Contact>\n
</Shipper>\n
<EProcShip>N</EProcShip>\n
<LabelImageFormat>PDF</LabelImageFormat>\n
<RequestArchiveDoc>Y</RequestArchiveDoc>\n
<Label>\n
<LabelTemplate>8X4_thermal</LabelTemplate>\n
<Logo>Y</Logo>\n
<Resolution>200</Resolution>\n
</Label>\n
</req:ShipmentValidateRequest>
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("/<OutputImage>(.*?)<\/OutputImage>/", $output, $matches);
$image = base64_decode($matches[1]);
$data['image'] = $image;
$data['demo'] = "demo.pdf";
return view('Administrator.shipments.dhl-post', $data);

A:

Your understanding of php's header function is slightly off.
Link to php header manual

header() is used to send a raw HTTP header. See the » HTTP/1.1
  specification for more information on HTTP headers.
Remember that header() must be called before any actual output is
  sent, either by normal HTML tags, blank lines in a file, or from PHP.
  It is a very common error to read code with include, or require,
  functions, or another file access function, and have spaces or empty
  lines that are output before header() is called. The same problem
  exists when using a single PHP/HTML file.

You should either temp save the file, use a stream, or link it from another page/route
PHP Temp File Manual
Since this doesn't answer the question, merely points out an incorrect use of header() I didn't want to post as answer, but did so by request

