LaravelDaily / laravel-invoices

Laravel package to generate PDF invoices from various customizable parameters
GNU General Public License v3.0
1.35k stars 296 forks source link

Unable to stream the pdf #228

Open SanthoshSivan-Dev opened 5 months ago

SanthoshSivan-Dev commented 5 months ago

Hi,

I am using the basic code you mentioned on the doc to generate a pdf. code mentioned below,

$customer = new Buyer([
    'name'          => 'John Doe',
    'custom_fields' => [
        'email' => 'test@example.com',
    ],
]);

$item = InvoiceItem::make('Service 1')->pricePerUnit(2);

$invoice = Invoice::make()
    ->buyer($customer)
    ->discountByPercent(10)
    ->taxRate(15)
    ->shipping(1.99)
    ->addItem($item);

return $invoice->stream();

when I load the pdf URL. I was getting errors like

Dompdf\Options::validateArtifactPath(): Argument # 1 ($path) must be of type string, null given, called in /home/krf/Documents/Projects/student-management/vendor/dompdf/dompdf/src/Options.php on line 1075

Laravel version: "^11.0" PHP version: "8.2"

is there any solution for this?

mustafaalharethi commented 1 month ago

Use this

return response()->streamDownload(function () use ($invoice) { echo $invoice->stream(); }, 'name.pdf');

if you want get PDF Link use this

$link = $invoice->url(); return redirect($link);