如何在MPDF中显示多个行数据?

发布于 2025-01-25 13:05:14 字数 3118 浏览 2 评论 0原文

我正在从事1个项目,在那里我要将文章转换为PDF。 当我将特定行生成PDF时,它正常工作。

但是现在,我想添加一个新功能,该功能将在单个PDF中生成多个行的PDF。

如果用户单击多个行,然后在PDF生成按钮上,则应在

下面的单个文件中生成PDF,这是我的代码

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();
    }
}
    }

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();
    }
}
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文