2011-03-18 12 views
1

Je suis nouveau à FPDF.Comment créer des fichiers PDF en utilisant PHP MySQL?

Mais j'essaie comme ci-dessous. Comment puis-je créer un PDF à partir de balises HTML en utilisant 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); 
    $pdf->Output(); 
?> 

ci-dessous est mon programme PHP

<?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); 
?> 
+2

duplication possible de [Comment créer un fichier PDF avec PHP?] (Http://stackoverflow.com/questions/4666171/how-to-create-a-pdf-file-with-php) –

+0

Depuis que vous êtes à l'aise avec HTML, vous pouvez envisager la [liste des convertisseurs HTML vers PDF] (http://stackoverflow.com/q/3178448/264628). Il couvre plus que des solutions basées sur PHP, mais il énumère une variété d'options. – BrianS

Répondre

0

code PHP pour convertir le HTML en PDF fonctionne très bien sur ma fin. Le code suivant convertit une page Web et envoie le PDF généré au navigateur:

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; 

Vous pouvez également convertir le code HTML brut, il suffit d'utiliser la méthode au lieu de convertURI() convertHtml():

$pdf = $client->convertHtml("<body>My HTML Layout</body>"); 
L'API

vous permet de convertir également un fichier HTML local:

$pdf = $client->convertFile("/path/to/MyLayout.html"); 

aller ici pour télécharger API Visit

Questions connexes