/    Sign up×
Community /Pin to ProfileBookmark

Create Link to generate PDF File

Hi,

Good day!

I have a query to display data from my database.
Now I display it in web page, but I need also to create a link to generate pdf file same as the web page display
Here is my code:

[code=php]
$query3 = “SELECT employee_no, arabic_name, fullname, nationality, join_date, passport_no, passport_end_date, res_no, res_end_date, company_work, company_sponsor
FROM tbl_employee_informations WHERE res_end_date = ‘$date_visa’ ORDER BY res_end_date”;

$res = $conn->query($query3);
$cnt = $res->num_rows;

<p>
echo”<a href=”expiring_visa_pdf.php” target=”_Blank” style=’float:left;margin:auto auto 10px auto;font-weight:bold;text-decoration:none; color:#8d735a;’>Generate PDF<a/>”;
echo “<p style=’float:left;margin:auto auto auto 350px;font-weight:bold; color:#8d735a;’>Total: $cnt </p>”;

echo “<div id=’report_one’>”;
echo “<table style=’border-radius:3px; border: 1px solid #a6a6a4;’>”;
echo “<tr style=’text-align:center;font-weight:bold; background-color:#FFF;’>”;
echo “<th class=’report_table’>EMPLOYEE NO.</th>”;
echo “<th class=’report_table’>ARABIC NAME</th>”;
echo “<th class=’report_table’>ENGLISH NAME</th>”;
echo “<th class=’report_table’>NATIONALITY</th>”;
//echo “<th class=’report_table’>JOIN DATE</td>”;
echo “<th class=’report_table’>PASSPORT NO.</th>”;
//echo “<th class=’report_table’>PASSPORT END DATE</th>”;
echo “<th class=’report_table’>RESIDENCY ID</th>”;
echo “<th class=’report_table’>RESIDENCY END DATE</th>”;
echo “<th class=’report_table’>COMPANY WORK</th>”;
echo “<th class=’report_table’>COMPANY SPONSOR</th>”;
echo “</tr>”;
while($row = $res->fetch_assoc())
{
$employee_no = $row[’employee_no’];
$fullname = $row[‘fullname’];
$fullname = utf8_encode($fullname);
$arabic_name = $row[‘arabic_name’];
$nationality = $row[‘nationality’];
$join_date = $row[‘join_date’];
$join_date = date(‘d-m-Y’,strtotime($join_date));
$passport_no = $row[‘passport_no’];
$passport_end_date = $row[‘passport_end_date’];
$passport_end_date = date(‘d-m-Y’,strtotime($passport_end_date));
$res_no = $row[‘res_no’];
$res_end_date = $row[‘res_end_date’];
$res_end_date = date(‘d-m-Y’,strtotime($res_end_date));
$company_work = $row[‘company_work’];
$company_sponsor = $row[‘company_sponsor’];

echo “<tr>”;
echo “<td class=’report_table’>$employee_no</td>”;
echo “<td class=’report_table’ dir=’RTL’>$arabic_name</td>”;
echo “<td class=’report_table’>$fullname</td>”;
echo “<td class=’report_table’>$nationality</td>”;
//echo “<td class=’report_table’>$join_date</td>”;
echo “<td class=’report_table’>$passport_no</td>”;
//echo “<td class=’report_table’>$passport_end_date</td>”;
echo “<td class=’report_table’>$res_no</td>”;
echo “<td class=’report_table’>$res_end_date</td>”;
echo “<td class=’report_table’>$company_work</td>”;
echo “<td class=’report_table’>$company_sponsor</td>”;
echo “</tr>”;
}

echo “</table>”;
echo “</div>”;
[/code]

Now, I need to convert this table form html to pdf once I click the Generate PDF.

I don’t know how to do that.

I started by this:

[CODE]
<?php
require(‘fpdf/fpdf.php’);

class PDF extends FPDF
{
// Page header
function Header()
{
// Logo
$this->Image(‘images/logo.png’,10,6,30);
// Arial bold 15
$this->SetFont(‘Arial’,’B’,15);
// Move to the right
$this->Cell(80);
// Title
$this->Cell(30,10,’Expiring Visa’);
// Line break
$this->Ln(20);
}

// Page footer
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-15);
// Arial italic 8
$this->SetFont(‘Arial’,’I’,8);
// Page number
$this->Cell(0,10,’Page ‘.$this->PageNo().’/{nb}’,0,0,’C’);
}
}

// Instanciation of inherited class
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont(‘Times’,”,12);
//for($i=1;$i<=40;$i++)
// $pdf->Cell(0,10,’Printing line number ‘.$i,0,1);
//$pdf->Cell();
$pdf->Output();

?>
[/CODE]

but in this code I can only show the logo and title

I hope someone can help me on this matter.

Thank you.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmAug 25.2015 — FPDF is a really good pdf creation tool that I have used for several years. It does however take a bit of learning to see how to organize the necessary calls to the different functions and make your output look the way you want.

You have to envision your output (pdf) page as a set of rows and columns. Those are managed in FPDF as x and y values. You can set the height of each row in your document, set the font size, and then position the 'cursor' at a certain x/y coordinate and use the Cell or MultiCell function to output some data. By setting the width of each cell you can then make successive calls to Cell/MultiCell to output other items on the same 'row' and eventually use the Ln function to move to the next row. Basically you have to lay out your planned document and then use a loop to call a function that makes all your output calls for each row of data.

A bit of a learning curve but once you get the knack it gets pretty easy. I would begin by reading thru the help to see what the different functions can do. You can also find some good help on their website.

PS - almost forgot. You state that your code only shows you the header and footer. Of course! You commented out any other output you wanted to generate.
×

Success!

Help @newphpcoder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...