Home » Php » I need to generate pdf file from php web page using wordpress?

I need to generate pdf file from php web page using wordpress?

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am developing a WordPress website, I need to generate pdf file for using html with php code. I have included libraries file but i am getting empty pdf page only i didn’t get any data.I have given below used my code. I am getting output image above

include_once('libs/fpdf.php');
require_once('html2pdf/html2pdf.class.php');

if(isset($_GET['user_id'])){
    $user_id = $_GET['user_id'];      
    $result = $wpdb->get_results( "SELECT * FROM wp_candi WHERE user_id=$user_id");

}
?>

<?php
foreach($result as $print){

    $content = '';
    $content .= '<h2 align="center"><br/><br/>CANDIDAE<br/><br/></h2>
       <form name="editfinalview" id="editfinalview" method="post" enctype="multipart/form-data" action="" style="background-color: #2e3137; border-radius:10px 10px 10px 10px;">
        <table style="width:600px;" align="center" border="1" cellpadding="6" cellspacing="1">
        <tr><td colspan="2" align="center" style=" font-size: 18px; padding: 25px; background-color: #454956; color: #ffffff;"><strong>IDENTIFICATION</strong></td></tr>
        <tr>
        <td width="30%" align="right" style="color: #000000; background-color: #F3F3F3; font-size: 15px; padding: 10px 10px 10px 100px;"  valign="top"><strong>Formation vis&eacute;e</strong></td>
            <td width="70%" align="left" style="color: #000000; background-color: #F3F3F3; font-size: 15px;  padding: 10px 100px 10px 10px; " valign="top"><span style="font-weight: bold; color: #ff9900;">'.$print->numFormCand.'</span></td>
        </tr>
        <tr>
            <td width="30%" align="right" style="color: #000000; background-color: #5d87a0; font-size: 15px;  padding: 10px 10px 10px 100px; "  valign="top"><strong>Par quel moyen avez-vous eu connaissance de cette formation ?</strong></td>
            <td width="70%" align="left" style="color: #000000; background-color: #5d87a0; padding: 10px 100px 10px 10px;  " valign="top"><span style="font-weight: bold; color: #ff9900;">'.$print->questionCand.'</span></td>
        </tr>';
}   

?>

  $pdf_name = $save_path."candidature".$ts.".pdf";

//$html2pdf = new HTML2PDF('P', 'A4', 'fr' true, 'UTF-8', array(0, 0, 0, 0));
$html2pdf = new HTML2PDF('L', 'A4', 'fr', true, 'UTF-8', array(0, 0, 0, 0));

//$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->writeHTML($content);
ob_end_clean();
$html2pdf->Output($pdf_name, 'I');[![enter image description here][1]][1]
      enter image description here
How to&Answers: