HOW TO GENERATE ARABIC PDF USING TCPDF

Dec 20, 2024 Copy Link

ุงู„ุณู„ุงู… ุนู„ูŠูƒู… ๐Ÿ‘‹

 

ุฌุงูŠ ุจุนุฏ ุบูŠุงุจ ุทูˆูŠู„ ุจู…ู‚ุงู„ุฉ ุจุณูŠุทุฉ ูˆ ู‡ุชูƒู„ู… ุนู† ู…ุดูƒู„ุฉ ูƒู„ ุงู„ุนุฑุจ ุจูŠู‚ุงุจู„ูˆู‡ุง ููŠ ู„ุงุฑููŠู„ ูˆ ู‡ูŠ ุฅู† ุฅุฒุงูŠ ุชุทุจุน PDF ุนุฑุจูŠ ู…ู† ุบูŠุฑ ุงูŠ ู…ุดูƒู„ุฉ ููŠ ุงู„ encoding ๐ŸŒ

 

 ู‡ู†ุณุชุฎุฏู… ุจุงูƒุฏุฌ TCPDF ููŠ ุงู„ู…ูˆุถูˆุน ุฏุง, ุชุนุงู„ูˆุง ุงู„ุฃูˆู„ ู†ุนู…ู„ู‘ู‡ุง install ุนู† ุทุฑูŠู‚ ุงู„ command ุฏุง ๐Ÿ‘‡

 

composer require tecnickcom/tcpdf

 

ูˆ ุฏู„ูˆู‚ุชูŠ ุจู‚ุง ุฌู‡ ูˆู‚ุช ุงู„ูƒูˆุฏ ๐Ÿ‘จ‍๐Ÿ’ป

 

use App\Models\User;
use TCPDF;

class PDFController extends Controller
{
    /**
     * Generate the PDF of the user then download it.
     */
    public function generate(User $user)
    {
        $filename = "{$user->name}.pdf";

        $pdf = new TCPDF(
            PDF_PAGE_ORIENTATION,
            PDF_UNIT,
            PDF_PAGE_FORMAT,
            true,
            'UTF-8',
            false
        );

        $pdf->SetTitle($user->name);
        $pdf->setRTL(true);
        $pdf->SetFont('aefurat', '', 16);

        $pdf->AddPage();

        $html = view('user.show', compact('user'))->render();

        $pdf->writeHTML($html, true, false, true, false, '');

        // Preview the PDF without storing and downloading it
        $pdf->Output(public_path($filename));

        // Store the PDF as a file then download it
        // $pdf->Output(public_path($filename), 'F');

        // Download the PDF directly without storing it
        // $pdf->Output(public_path($filename), 'D');

        // > [!NOTE]
        // > You can also create a mix between two of these flags...

        return response()->download(public_path($filename));
    }
}

 

ุฎู„ูŠ ุจุงู„ูƒ ุงู† ุงู„ุจุงูƒุฏุฌ ุฏูŠ sensitive ููŠ ุงู„ HTML Tags ูุง ู„ูˆ ู†ุณูŠุช ุชู‚ูู„ ุชุงุฌ ุงูˆ ูƒุชุจุชู‡ ุบู„ุท ู‡ูŠุทู„ุนู„ูƒ ุฅูƒุณุจุดู†.

 

ูˆ ุฏุง example ุฎุงุต ุจุงู„ุจุงูƒุฏุฌ ุจูŠูˆุถุญ ุฅุฒุงูŠ ุชุนู…ู„ ูƒุฏุง ุจุดูƒู„ ู…ููุตู„ ุงูƒุชุฑ...๐Ÿง

 

ูˆ ุจูƒุฏุง ุฃูƒูˆู† ุฎู„ุตุช ูˆ ุฃุชู…ู†ูŠ ุชูƒูˆู† ุฅุณุชูุฏุช โœ”

Share via

Mahmoud Ramadan

Mahmoud Ramadan

Mahmoud is the creator of Digging Code and a contributor to Laravel since 2020.

Newly published

  • How to Enable Relationship Autoloading in Versions Before v12.8

    How to Enable Relationship Autoloading in Versions Before v12.8

    PREMIUM

  • Get your environment ready to welcome Laravel v12

    Get your environment ready to welcome Laravel v12

    PREMIUM

  • How to generate Arabic PDF using TCPDF

    How to generate Arabic PDF using TCPDF

    FREE