FPDF for creating pdf diplomas
Before anything else, I must say I am new on building WordPress functions. I have a website with online courses. Students have to sit exams and at the end they get a score, an average of all the exams. I am trying to build a simple dynamic PDF diploma with their name and average score, no more, which I will download by clicking on a button from a table/list. I found the class FPDF, unzipped it and uploaded it through FTP. Then, I made an include( 'fpdf183/fpdf.php');
on my functions.php in order to retrieve the class FPDF. After that, I went to my student-page.php and wrote this code to create the PDF:
$sql =SELECT DISTINCT(ID),`user_registered`...();
$request = $wpdb-get_results($sql); ?
table id=example class=display cell-border compact stripe style=width:100%
thead
tr
thName/th
thAverage score/th
thDownload Diploma/th
/tr
/thead
tbody
foreach ($request as $value) {
$pdf = new FPDF();
if( isset($_POST['generate_pdf'])){
global $pdf;
$title_line_height = 10;
$content_line_height = 8;
$pdf-AddPage();
$pdf-SetFont( 'Arial', '', 42 );
$pdf-Write(20, 'This is a sample');
$pdf-Write(20, $value-name);
$pdf-Write(20, $value-average);
$pdf-Output('D','sample.pdf');
}
tr
td?php echo $value-name ?/td
td?php echo $value-average ?/td
td
form method=post id=as-fdpf-form
button class=button button-primary type=submit name=generate_pdf value=generateDownload/button
/form
/td
/tr
/tbody
/table
I didn't copy the whole code, just the most important so that you get the idea. I do not know what I am doing wrong (maybe everything), but I would appreciate your help. :)