Problem Convert HTML table to pdf using tcpdf

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
totoylubacon
Forum Newbie
Posts: 7
Joined: Thu Mar 01, 2012 5:48 am

Problem Convert HTML table to pdf using tcpdf

Post 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>

?>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Problem Convert HTML table to pdf using tcpdf

Post 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
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: Problem Convert HTML table to pdf using tcpdf

Post 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.
Post Reply