Generate an MPDF to PDF with HTML and PHP

孤街浪徒 提交于 2020-01-05 13:51:58

问题


This the my code a CV that I want to create an MPDF with and underneath I have the MPDF code that is on another page. The content is appearing on the pdf but with php echo values when i want the actual php values instead

<?php
            //Image upload
            $uploaddir = "images\\";
            $uploadfile = $uploaddir . $userTime . basename($_FILES['myimg']['name']); 
            move_uploaded_file($_FILES["myimg"]["tmp_name"], "$uploadfile");
            $_SESSION['myimg'] = $uploadfile;

            if(isset($_FILES['myimg'])){
                $file = $_FILES['myimg']['name'];
                //echo "" .$file;
                //echo "<img src='" . $file . "'>";
                echo '<img src="' . $uploadfile . '" width="40%" height="40% "/>'; 
            }
        ?>
        <p>First Name<br><?php echo $fullName;?></p> 
        <p>Email Address<br><?php echo $emailAddress;?></p>
        <p>Phone Number<br><?php echo $phoneNumber;?></p>`enter code here`
        <p>College<br><?php echo $theEducation;?></p>
        <p>Course<br><?php echo $theCourse;?></p>

<?php

require_once __DIR__ . '/vendor/autoload.php';

    $mpdf = new \Mpdf\Mpdf();

    // $mpdf->WriteHTML(file_get_contents('build.php'));

    $mpdf->Output();
    //$mpdf->Output('filename.pdf','F');

?>

回答1:


Either build your HTML content to a string:

$html = '';
...
$html .= '<img src="' . $uploadfile . '" width="40%" height="40% "/>'
$html .= '<p>First Name<br>' . $fullName . '</p> 
<p>Email Address<br>' . $emailAddress . '</p>
<p>Phone Number<br>' . $phoneNumber . '</p>
<p>College<br>' . $theEducation . '</p>
<p>Course<br>' . $theCourse . '</p>';

Or use output buffering to capture the html.

Then, pass the HTML to mPDF:

$mpdf->WriteHTML($html);


来源:https://stackoverflow.com/questions/53130693/generate-an-mpdf-to-pdf-with-html-and-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!