1. Go to this page and download the library: Download vaneetjoshi/laravel-pdf library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Vaneetjoshi\LaravelPdf\Facades\Pdf;
use Illuminate\Support\Facades\Mail;
public function sendInvoiceEmail($user)
{
$data = ['name' =>$user->name, 'amount' => 1500];
// 1. Generate the raw PDF binary string in memory
$pdfData = Pdf::paperSize('A4')
->loadView('pdf.invoice', $data)
->output();
// 2. Attach the raw data directly to the email
Mail::send('emails.billing', $data, function($message) use ($user,$pdfData) {
$message->to($user->email)
->subject('Your Recent Invoice')
->attachData($pdfData, 'Invoice.pdf', [
'mime' => 'application/pdf',
]);
});
return response()->json(['message' => 'Invoice emailed successfully!']);
}
[
'border_bg_color' => '#ffffff', // (string|null) Outer track hex color
'border_line_color' => '#000000', // (string) Inner framing line hex color
'border_line_width' => '1px', // (string) CSS line thickness ('0' for none)
'border_size_mm' => 12.0, // (float) Total border thickness in mm
'padding_mm' => 2.0, // (float) Distance between line and track in mm
'inner_margin_mm' => 5.0, // (float) Safe margin between line and body text
// Edge Sections: 'top', 'bottom', 'left', 'right'
'top' => [
'text' => 'ॐ', // (string) Text string or character to render
'image' => '', // (string) URL or path to image
'align' => 'center', // (string) 'left', 'center', 'right'
'color' => '#000000',// (string) Text hex color
'font_size' => 12, // (int) Font size in px
'with_sanskrit' => true, // (bool) Enable Devanagari font for this edge
'repeat' => true, // (bool) Repeat text/symbol across the edge length
'gap' => 10.0 // (float) Spacing between repeated items in mm
]
]