Export PDF with mPDF library

42 Views Asked by At

The issue arises when attempting to export a file written in Arabic to PDF format as it does not display the Arabic text correctly, instead converting it to symbols.

<?php
session_start();


include('conn.php');
require 'vendor/autoload.php'; // Include Composer's autoloader

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use Mpdf\Mpdf;

// Check if NumInscription is provided in the URL
if (isset($_GET['NumInscription'])) {
    $numInscription = $_GET['NumInscription'];

    // Fetch student details based on NumInscription
    try {
        $sql = "SELECT * FROM Eleve WHERE NumInscription = ?";
        $stmt = $conn->prepare($sql);
        $stmt->bindParam(1, $numInscription);
        $stmt->execute();
        $studentDetails = $stmt->fetch(PDO::FETCH_ASSOC);

        // Check if the student exists
        if (!$studentDetails) {
            echo "Student not found.";
            exit;
        }
    } catch (PDOException $e) {
        echo "Error: " . $e->getMessage();
    }

    // Function to generate PDF and output it
    function generateAndOutputPDF($studentDetails)
    {
        $mpdf = new Mpdf(['mode' => 'utf8mb4_general_ci', 'format' => 'A2']); 

        // Output PDF as a download
        $mpdf->Output('certificate_' . $studentDetails['NumInscription'] . '.pdf', 'D');
    }

    // Check if download button is clicked
    if (isset($_POST['download'])) {
        generateAndOutputPDF($studentDetails);
        exit;  
    }
} else {
    echo "NumInscription parameter is missing.";
    exit;
}
?>

i try to change the language in the html code into the file after exported but deosn't workI try to change the language in the HTML code in the file after exporting, but it doesn't work.

0

There are 0 best solutions below