how to display multiple row data into mpdf?

Viewed 59

I'm working on 1 project where I'm going to convert articles into pdf. it's working properly when I generate a particular row into a pdf.

But now I want to add a new feature which will generate pdf for multiple rows into a single pdf.

If the user clicks on multiple rows, and then on the pdf generate button, then it should generate pdf in a single file

Below is my code

if ((isset($_GET['art_id']) && $_GET['art_id'] !== '') || isset($_POST['bulk_data'])) {
    if (isset($_POST['bulk_data'])) {
        $id = $_POST['check_id'];
        foreach ($id as $i) {
            $fetch_order = $db->selectJoin("SELECT a.*, t.* FROM article_format AS a LEFT JOIN teachers AS t ON a.user_id = t.teach_id WHERE a.art_id = $i");
            $result = $db->getResult();
        }
    } else {
        $fetch_order = $db->selectJoin("SELECT a.*, t.* FROM article_format AS a LEFT JOIN teachers AS t ON a.user_id = t.teach_id WHERE a.art_id = {$_GET['art_id']}");
        $result = $db->getResult();
    }
    foreach ($result as $data) {
        $cat_id = $data['cat_id'];
        $art_name = $data['art_name'];
        $type = $data['art_type'];
        $post_date = $data['post_date'];
        $content = $data['content'];
        $images = $data['main_img'];
        $img = explode(',', $images);
        $role = $data['role'];

        if ($role == 'admin') {
            $teah_name = 'Admin';
        } else {
            $teah_name = $data['teach_name'];
        }
$content = htmlspecialchars_decode($content);
    if ($type == 'format1') {
        $html = '<div class="container">
                    <div class="col-12">
                        <div class="heading">
                            <h5>' . $art_name . '</h5>
                        </div>
                        <div class="col-md-4">
                            <div class="users">
                                <span>' . $teah_name . '</span>
                                <span id="date">' . date('d M', strtotime($post_date)) . '</span>
                            </div>
                        </div>
                        <br>
                        <img src="./uploads/' . $img[0] . '" width="300px" height="300px" id="main_img" align="right" style="float:right" />
                        ' . $content . '
                            <div class="other_images">
                            <div style="background-image:url(' . "./uploads/$img[1]" . '); background-size:cover; background-repeat: no-repeat; width:100%; height:250px">
                            </div>
                        </div>
                    </div>
                </div>';
    }
    ob_end_flush();
    try {
        if (isset($_GET['type']) && $_GET['type'] == 'ppt') {
            $mpdf = new \Mpdf\Mpdf(['mode' => 'utf-8', 'format' => 'A4-L']);
        } else {
            $mpdf = new \Mpdf\Mpdf();
        }
        $css = file_get_contents('./pdf.css');
        // $mpdf->AddPage('L');
        $mpdf->WriteHTML($css, 1);
        $mpdf->WriteHTML($html, 2);
        $mpdf->Output();
    } catch (\Mpdf\MpdfException $e) {
        echo $e->getMessage();
    }
}
    }
0 Answers
Related