PHP code example of mostafamoknaa / laravel-arabic-pdf

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

    

mostafamoknaa / laravel-arabic-pdf example snippets


use MostafaMoknaa\ArabicPdf\Facades\ArabicPdf;

class InvoiceController
{
    public function show(Invoice $invoice)
    {
        return ArabicPdf::loadView('pdf.invoice', ['invoice' => $invoice])
            ->stream('invoice.pdf');      // show in the browser
    }

    public function download(Invoice $invoice)
    {
        return ArabicPdf::loadView('pdf.invoice', ['invoice' => $invoice])
            ->setPaper('a4', 'landscape')
            ->download('فاتورة.pdf');      // download (Arabic file names work)
    }
}

$pdf = ArabicPdf::loadView('view.name', $data);   // from a Blade view
$pdf = ArabicPdf::loadHTML('<p>مرحبا</p>');       // from an HTML string
$pdf = ArabicPdf::loadFile('/path/to/file.html'); // from an HTML file

$pdf->setPaper('a4', 'portrait');                 // paper size and orientation
$pdf->setOption('isRemoteEnabled', true);         // any dompdf option

$pdf->stream('file.pdf');                         // inline response
$pdf->download('file.pdf');                       // download response
$pdf->save(storage_path('app/file.pdf'));         // save to disk
$pdf->output();                                   // raw PDF string
$pdf->html();                                     // processed HTML (debugging)
$pdf->getDompdf();                                // the underlying Dompdf instance

use Barryvdh\DomPDF\Facade\Pdf;
use MostafaMoknaa\ArabicPdf\Facades\Arabic;

$html = Arabic::html(view('pdf.invoice', $data)->render());

return Pdf::loadHTML($html)->download('invoice.pdf');

Arabic::fix('مرحبا بكم');                 // shaped + visual order, lines separated by "\n"
Arabic::fix('نص طويل ...', 60);           // wrapped every 60 characters
Arabic::fixForHtml("سطر\nسطر آخر");       // escaped, lines joined with <br>
Arabic::shape('مرحبا');                   // connect the letters only
Arabic::containsArabic('Hello مرحبا');    // true

// config/arabic-pdf.php
return [
    'paper' => 'a4',
    'orientation' => 'portrait',
    'default_font' => 'DejaVu Sans',
    'strip_harakat' => false,          // remove diacritics (tashkeel)
    'max_chars_per_line' => null,      // wrap long Arabic paragraphs globally
    'rtl_css' => true,                 // right-align dir="rtl" elements
    'reverse_table_columns' => true,   // RTL tables inside dir="rtl"
    'dompdf' => [ /* any Dompdf\Options option */ ],
];
bash
php artisan vendor:publish --tag=arabic-pdf-config