top of page

Using MPDF to create Professiona Certificate

  • Writer: سُلَيْمَان بْن دَاوُوْد
    سُلَيْمَان بْن دَاوُوْد
  • Jun 6, 2020
  • 3 min read

The MPDF is a handy tool to create the PDF's and you can create them as ease here is what we created 2 PDF and the code is as below


You can include external style sheet like


filename = "".get_stylesheet_directory()."/style.css";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
ob_clean();
$mpdf = new mPDF('','', 0, '', 10, 10, 10, 10, 0,0, 'L');
$mpdf->WriteHTML($contents,1);
$mpdf->WriteHTML($pdf,2);

//Write To Disk
$mpdf->Output(get_stylesheet_directory().'/pdf/'.$user_details['display_name'].'-Offer-'.date('d.M.Y').'.pdf','F');
//Download To Browser
$mpdf->Output($user_details['display_name'].'-Offer-'.date('d.M.Y').'.pdf','D');

A Full Blows Example of Profession Certificate is below followed by code used to create it.



<?php 
$type = sanitize_text_field($_GET['type']);
ob_start();
$Plugin_path          = plugins_url().'/custom_member_directory/templates/img/';
include_once('mpdfnew/vendor/autoload.php');
$current_user_id      = get_current_user_id();
$user_info            = get_userdata($current_user_id);
$username             = $user_info->user_login;
$username             = $user_info->user_login;
$first_name           = $user_info->first_name;
$last_name            = $user_info->last_name;
$Certification_number = get_user_meta($current_user_id,'certification_number',true);
$Certification_date   = date('d M Y');
$membership_category  = unserialize(get_user_meta($current_user_id,'membership_category',true));
$After_implod         = implode(',',$membership_category);
$Certification_name   = $first_name.' '.$last_name;
$imgPath              = $Plugin_path.'/head.jpg';
$backImgpath          = $Plugin_path.'/globe2.jpg';
$mpdf                 = new \Mpdf\Mpdf([
    'mode'        => 'utf-8',
    'format'      => 'Letter-L',
    'orientation' => 'L',
]);
$content ='';   
if(in_array($type, $membership_category) && $type == 'CP'){
    $content .='<!DOCTYPE html>
    <html lang="en">
    <head>
    <!-- meta Tags start here -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <!-- <link rel="icon" href="app/images/favicon.png" type="image/x-icon" /> -->
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=0" />
    <title>TEP Certificate</title>
    <style>
    
    .certificatewrapper{
        background:url("'.$backImgpath.'") no-repeat;
        background-size:contain;
        background-position: center;
    }
    
    @media(max-width: 991px){
     
        .certificatewrapper h5{
            font-size: 30px !important;
        }
        .certificatewrapper h4{
            font-size: 35px !important;  
        }
        .certificatewrapper h3{
            font-size: 40px !important; 
        }
        .certificatewrapper p{
            font-size: 20px !important;
        }
        .certificatewrapper .specialp p{
            font-size: 14px !important;
        }
        .certificate-lines p span{
            width: 90px !important;
        }
    }
    </style>
    </head>
    <body style="padding:4vw 4vw;margin:0px;font-family: Lato, sans-serif;font-weight: 400;">';
    $content .= '<div><img style="width:100%;" src="'.$imgPath.'" ></div>';
    $content .='<div class="certificatewrapper" >
    <div>
    <h5 style="font-size:20px;color: #231f20;text-align: center;letter-spacing: 1px;font-weight: 400;margin: 0px;padding:10px 0px 5px;">
    Let It Be Known That</h5>
    </div>
    <div>
    <h3
    style="font-size: 30px;color: #231f20;text-align:center;letter-spacing: 1px;font-weight: bold;margin: 0px;padding:5px 0px 15px;font-family: lucida;">
    '.$Certification_name.', '. $type.'</h3>
    </div>
    <div style="padding: 0px 10px;">
    <p style="font-size: 16px;color: #231f20;text-align: center;margin: 0px;padding: 5px 0px 5px;">
    Has completed 780 Hours of training, and one year of supervised practice in psychodrama, sociometry and
    group psychotherapy, passed both a written and an on‐site examination and is certified as a
    </p>
    </div>
    <div>
    <h5
    style="font-size:28px;color: #231f20;text-align: center;letter-spacing: 1px;font-weight: 400;margin: 0px;padding:10px 0px 10px;line-height: 30px;">
    Practitioner <br>In <br>Psychodrama, Sociometry & Group Psychotherapy
    </h5>
    </div>
    <div style="text-align: center;" class="specialp">
    <span style="font-size:34px;line-height:36px;text-align: center;font-weight: 400;margin: 0px;padding: 30px 10px 0px;border-bottom: 2px solid #231f20;color: #231f20;display:inline-block; font-family: dancing;">Catherine D.Nugent, L.C.P.C., T.E.P</span>
    <p style="font-size: 12px;text-align: center;font-weight: 400;margin: 0px;color: #231f20;padding: 10px 0px 20px;">President, American Board of Examiners in Psychodrama, Sociometry & Group Psychotherapy</p>
    </div>
    <div style="text-align: center;padding: 20px 0px 0px;width:100%" class="certificate-lines"> 
    <p style="width:33.3%;display:inline-block;margin:0px;float:left;font-size: 13px;color: #231f20;padding:0px 0px;">Certification Date:<span style="width: 130px;display: inline-block;margin-left: 7px;border-bottom: 1px solid #231f20;">'.date('m/d/Y',strtotime($Certification_date)).'</span>  </p>
    <p style="width:33.3%;display:inline-block;margin:0px;float:left;font-size: 13px;color: #231f20;padding:0px 0px;">Expiration Date: <span style="width: 130px;display: inline-block;margin-left: 7px;border-bottom: 1px solid #231f20;"> 01 Jan 2021</span> </p>
    <p style="width:33.%;display:inline-block;margin:0px;float:left;font-size: 13px;color: #231f20;padding:0px 0px;">Certification No.:<span style="width: 130px;display: inline-block;margin-left: 7px;border-bottom: 1px solid #231f20;">'.$Certification_number.'</span></p>
    </div>
    </div>';
    
    $content .= '</body></html>';
    
    $mpdf->autoScriptToLang = true;
    $mpdf->autoLangToFont = true;
    $mpdf->WriteHTML($content);
    //$mpdf->Output();
    $mpdf->Output($type.'_'.$Certification_number.'_'.date('m.d.Y').'.pdf','I');
}
if(in_array($type, $membership_category) && $type == 'TEP'){
    $content .='<!DOCTYPE html>
    <html lang="en">
    <head>
    <!-- meta Tags start here -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <!-- <link rel="icon" href="app/images/favicon.png" type="image/x-icon" /> -->
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=0" />
    <title>TEP Certificate</title>
    <style>
    
    .certificatewrapper{
        background:url("'.$backImgpath.'") no-repeat;
        background-size:contain;
        background-position: center;
    }
    
    @media(max-width: 991px){
     
        .certificatewrapper h5{
            font-size: 30px !important;
        }
        .certificatewrapper h4{
            font-size: 35px !important;  
        }
        .certificatewrapper h3{
            font-size: 40px !important; 
        }
        .certificatewrapper p{
            font-size: 20px !important;
        }
        .certificatewrapper .specialp p{
            font-size: 14px !important;
        }
        .certificate-lines p span{
            width: 90px !important;
        }
    }
    </style>
    </head>
    <body style="padding:4vw 4vw;margin:0px;font-family: Lato, sans-serif;font-weight: 400;">';
    $content .= '<div><img style="width:100%;" src="'.$imgPath.'" ></div>';
    $content .='<div class="certificatewrapper" >
    <div>
    <h5 style="font-size:20px;color: #231f20;text-align: center;letter-spacing: 1px;font-weight: 400;margin: 0px;padding:10px 0px 5px;">
    Let It Be Known That</h5>
    </div>
    <div>
    <h3
    style="font-size: 30px;color: #231f20;text-align:center;letter-spacing: 1px;font-weight: bold;margin: 0px;padding:5px 0px 15px;font-family: lucida;">
    '.$Certification_name.', '. $type.'</h3>
    </div>
    <div style="padding: 0px 10px;">
    <p style="font-size: 16px;color: #231f20;text-align: center;margin: 0px;padding: 5px 0px 5px;">
    Has previously been certified as a practitioner (completing 780 Hours of training,<br>
    one year of supervised practice, and passed both a written and an on‐site examination);<br>
    has completed an additional three years of progressively responsible training, supervision and
    professional<br>
    development as a trainer, educator and practitioner in psychodrama, sociometry and group psychotherapy<br>
    and has passed both a written and an on‐site examination and is certified as a
    </p>
    </div>
    <div>
    <h5
    style="font-size:28px;color: #231f20;text-align: center;letter-spacing: 1px;font-weight: 400;margin: 0px;padding:10px 0px 10px;line-height: 30px;">
    Trainer, Educator & Practitioner <br>In <br>Psychodrama, Sociometry & Group Psychotherapy
    </h5>
    </div>
    <div style="text-align: center;" class="specialp">
    <span style="font-size:34px;line-height:36px;text-align: center;font-weight: 400;margin: 0px;padding: 30px 10px 0px;border-bottom: 2px solid #231f20;color: #231f20;display:inline-block; font-family: dancing;">Catherine D.Nugent, L.C.P.C., T.E.P</span>
    <p style="font-size: 12px;text-align: center;font-weight: 400;margin: 0px;color: #231f20;padding: 10px 0px 20px;">President, American Board of Examiners in Psychodrama, Sociometry & Group Psychotherapy</p>
    </div>
    <div style="text-align: center;padding: 20px 0px 0px;width:100%" class="certificate-lines"> 
    <p style="width:33.3%;display:inline-block;margin:0px;float:left;font-size: 13px;color: #231f20;padding:0px 0px;">Certification Date:<span style="width: 130px;display: inline-block;margin-left: 7px;border-bottom: 1px solid #231f20;">'.date('m/d/Y',strtotime($Certification_date)).'</span>  </p>
    <p style="width:33.3%;display:inline-block;margin:0px;float:left;font-size: 13px;color: #231f20;padding:0px 0px;">Expiration Date: <span style="width: 130px;display: inline-block;margin-left: 7px;border-bottom: 1px solid #231f20;"> 01 Jan 2021</span> </p>
    <p style="width:33.%;display:inline-block;margin:0px;float:left;font-size: 13px;color: #231f20;padding:0px 0px;">Certification No.:<span style="width: 130px;display: inline-block;margin-left: 7px;border-bottom: 1px solid #231f20;">'.$Certification_number.'</span></p>
    </div>
    </div>';
    
    $content .= '</body></html>';
    
    $mpdf->autoScriptToLang = true;
    $mpdf->autoLangToFont = true;
    $mpdf->WriteHTML($content);
    //$mpdf->Output();
    $mpdf->Output($type.'_'.$Certification_number.'_'.date('m.d.Y').'.pdf','I');
}
?>

Recent Posts

See All
Hide Upcoming Events

Hiding Upcoming Events can be relatively useful when you are using ACF fields to show Dates for an an Event The Following Snippet is an...

 
 
 

Comments


© 2020 by syednazrulhassan

bottom of page