How to create PDF files using PHP MySQL?
I am new to FPDF.
But i am trying like below. How can I create a PDF from HTML tags using FPDF?
<?php
require('fpdf.php');
include (connection.php)
$result = mysql_query("SELECT * FROM emp");
<!--- I don't know how to add the html tag here -->
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);开发者_JAVA百科
$pdf->Output();
?>
below is my PHP program
<?php
include (connection.php)
$result = mysql_query("SELECT * FROM emp");
?>
<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td> <?php print $row['FirstName']; ?></td>
<td> <?php print $row['LastName']; ?></td>
</tr>
<?php
}
?>
</table>
<?php
mysql_close($con);
?>
I think you should consider to use HTML2FPDF
Usage example available at the bottom of this blog post.
Check as well this other SO question: https://stackoverflow.com/questions/910243/how-to-convert-an-html-to-pdf-in-php-using-fpdf-lib-1-6
PHP code to convert HTML to PDF works fine on my end. The following code converts a web page and sends the generated PDF to the browser:
require 'pdfcrowd.php';
// create an API client instance
$client = new Pdfcrowd("username", "apikey");
// convert a web page and store the generated PDF into a variable
$pdf = $client->convertURI('http://www.google.com/');
// set HTTP response headers
header("Content-Type: application/pdf");
header("Cache-Control: max-age=0");
header("Accept-Ranges: none");
header("Content-Disposition: attachment; filename=\"google_com.pdf\"");
// send the generated PDF
echo $pdf;
You can also convert raw HTML code, just use the convertHtml() method instead of convertURI():
$pdf = $client->convertHtml("<body>My HTML Layout</body>");
The API lets you also convert a local HTML file:
$pdf = $client->convertFile("/path/to/MyLayout.html");
go here for download API Visit
精彩评论