Page 1 of 1

Problem Convert HTML table to pdf using tcpdf

Posted: Sat Jul 07, 2012 7:25 am
by totoylubacon
Please help... I want to convert my php html table populated with data coming from mysql table to pdf using tcpdf classes, but i don't know how to start, below is the excerpt code, that i want to convert in pdf. I want the php html table code below convert to pdf once i click the convert to pdf link. Please help me on how to do this.

Thanks.

<?php
ob_start();
if (!isset($_SESSION)) {
session_start();
}
require 'con/db.php';

$sem = isset($_GET['sms']) ? mysql_real_escape_string(htmlentities(trim($_GET['sms']))) : "";
$sy = isset($_GET['syr']) ? mysql_real_escape_string(htmlentities(trim($_GET['syr']))) : "";

$sqlGetStud = @mysql_query("SELECT student.STUDENTNUM,student.FNAME, student.MNAME, student.LNAME,student.GENDER FROM student
INNER JOIN registration ON student.STUDENTNUM=registration.STUDENTNUM
WHERE registration.SEMESTER='$sem' AND registration.SY='$sy' ORDER BY student.LNAME,student.FNAME");

echo '<table width=75%>';

echo '<table border=1 width=95%>';
echo '<tr><td ><center><b>Name of Students</b></center><td ><center><b>ID NO.</b></center></td>';
while($rs = mysql_fetch_array($sqlGetStud)){

$name = $rs['LNAME'].',' .'&nbsp;' .$rs['FNAME'] .'&nbsp;' .$rs['MNAME'];
echo '<tr border=1><td>'.$name .'<td>'.$rs['STUDENTNUM'].'</td></tr>';
}
</table>

?>

Re: Problem Convert HTML table to pdf using tcpdf

Posted: Mon Jul 09, 2012 2:09 pm
by social_experiment
http://bg2.php.net/manual/en/pdf.examples-basic.php
^ the php manual entry about creating pdfs and below (if you haven't found it already) the examples page of tcpdf
http://www.tcpdf.org/examples.php

Re: Problem Convert HTML table to pdf using tcpdf

Posted: Mon Jul 09, 2012 2:22 pm
by tr0gd0rr
Check out dompdf. It coverts any HTML to pdf and can apply most CSS rules. I've used it on many projects including tables with variable width columns--even 30 columns wide. It works really well.