This code give me 200 but did not stream generated pdf file..
I want to generate a invoice as pdf format and steam on browser but it didn’t work.
<?php
namespace App\Http\Traits;
use App\Models\Settings\POSSetting;
use Barryvdh\DomPDF\Facade\Pdf;
trait InvoiceTrait
{
protected function handleInvoice($request, $resource = null, $action, $name)
{
// Fetch the POS settings and invoice template
$posSetting = POSSetting::first();
// Generate dynamic invoice data
$invoice = $this->generateInvoiceData($request, $resource);
if ($request->has('for') && $request->for == 'pos') {
if ($posSetting->invoice_of_pos == 'Thermal') $invoiceBody = $posSetting->thermal_invoice;
if ($posSetting->invoice_of_pos == 'A4') $invoiceBody = $posSetting->a4_invoice;
}
if ($request->has('for') && $request->for == 'inventory') {
if ($posSetting->invoice_of_inventory == 'Thermal') $invoiceBody = $posSetting->thermal_invoice;
if ($posSetting->invoice_of_inventory == 'A4') $invoiceBody = $posSetting->a4_invoice;
}
// Replace the placeholders in the invoice body with actual data
$invoice = $this->replacePlaceholders($invoiceBody, $invoic`your text`e);
$pdf = Pdf::loadHTML($invoice)->setPaper('a4', 'portrait');
return $pdf->stream('invoice.pdf')
->header('Content-Type', 'application/pdf')
->header('Content-Disposition', 'inline; filename="invoice.pdf"');
}
}
Output :
Headers General
Headers Response
You need to sign in to view this answers