PHP code example of baidouabdellah / laravel-arpdf
1. Go to this page and download the library: Download baidouabdellah/laravel-arpdf 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/ */
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Baidouabdellah\LaravelArpdf\ArPDF;
class PdfController extends Controller
{
public function generatePdf()
{
$pdf = app(ArPDF::class);
// Example of adding text
$pdf->addText(50, 800, 12, 'Hello World');
$pdf->addArabicText(50, 780, 12, 'مرحبا بالعالم');
// Save or stream the PDF
$pdf->save('output/sample.pdf');
// Or stream directly to the browser
// $pdf->stream('document.pdf');
}
}
$pdf = app('ArPDF');
$pdf->setFont('path/to/your/font.ttf'); // Specify the path to your Arabic font
$pdf = app('ArPDF');
$pdf->setTitle('Sample PDF');
$pdf->addPage();
$pdf->setFont('resources/fonts/YourArabicFont.ttf');
$pdf->writeHTML('<h1>مرحبا بالعالم</h1>'); // Example of Arabic text
$pdf->output('sample.pdf');