PHP code example of sahifa / laravel

1. Go to this page and download the library: Download sahifa/laravel 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/ */

    

sahifa / laravel example snippets


use Sahifa\Laravel\Facades\Sahifa;

return Sahifa::pdfFromView('invoices.show', ['invoice' => $invoice])->download('invoice.pdf');

$pdf = Sahifa::pdfFromView('invoices.show', ['invoice' => $invoice], [
    'format' => 'A4',
    'margin' => '15mm',
    'footer' => ['source' => '<div style="width:100%;text-align:center;font-size:9px">صفحة {{page}} من {{total}}</div>'],
]);

return $pdf->download("invoice-{$invoice->number}.pdf"); // or ->inline()
$pdf->store("invoices/{$invoice->number}.pdf", 's3');     // any filesystem disk
$pdf->save(storage_path('app/invoice.pdf'));              // local path
$bytes = $pdf->content();                                 // raw bytes, e.g. for a Mailable attachment

Sahifa::pdf('<h1>Hello</h1>');
Sahifa::pdf('https://example.com/report/42', ['landscape' => true]);

Sahifa::screenshot(['url' => 'https://example.com', 'full_page' => true, 'format' => 'png'])
    ->store('screens/home.png');

use Illuminate\Mail\Attachment;

public function attachments(): array
{
    $pdf = Sahifa::pdfFromView('invoices.show', ['invoice' => $this->invoice]);

    return [Attachment::fromData(fn () => $pdf->content(), 'invoice.pdf')->withMime('application/pdf')];
}

use Sahifa\Laravel\Exceptions\SahifaException;

try {
    $pdf = Sahifa::pdfFromView('invoices.show', $data);
} catch (SahifaException $e) {
    if ($e->status === 402) { /* monthly allowance used up */ }
    report($e);
}

Http::fake(['api.sahifa.dev/*' => Http::response('%PDF-1.7', 200)]);

php artisan vendor:publish --tag=sahifa-config