I want to write data from a HTML form into a PDF document. Here's my code:
我想将HTML表单中的数据写入PDF文档。这是我的代码:
(home.php)
<!doctype HTML>
<html>
<body>
<form action="test.php" method="post">
NAME:<input type="text" name="name" ><br><br>
E-mail:<input type="text" name="email"><br><br>
Submit:<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])){
if(empty($_POST['name'])){
echo "fill"."<br><br>";
}
if(empty($_POST['email'])){
if(empty($_POST['name'])){
echo "check";
}
}
}
?>
(test.php)
<?php
require('fpdf.php');
class PDF extends FPDF {
function Header() {
$this->SetFont('Helvetica','B',15);
$this->SetXY(50, 10);
$this->Cell(0,10,'This is a header',1,0,'C');
}
function content() {
$html = '<table>
<tr>
<td>'.$_POST['name'].'</td>
</tr>
<tr>
<td>'.$_POST['email'].'</td>
</tr>
</table> ';
$this->write($html);
}
function Footer() {
$this->SetXY(100,-15);
$this->SetFont('Helvetica','I',10);
$this->Write (5, 'This is a footer');
}
}
$pdf=new PDF();
$pdf->AddPage();
$pdf->Output();
?>
1 个解决方案
#1
0
by changing libraries name i got the answer.
hope yhis will help you to.
<?php
require('htmlFPDF/html2fpdf.php');
$pdf=new HTML2FPDF();
$pdf->AddPage();
$fp = fopen("sample.html","r");
$strContent = "<table style='width:100%; border=1px solid black;padding:5px;'>
<thead>
<tr>
<td><h1 style='text-align:center'><b>Your submitted data is</b></h1></td>
</tr>
<tr>
<td>Name</td>
<td>$_POST[name]</td></tr>
<tr>
<td>Email</td>
<td>$_POST[email]</td></tr>
<tr>
<td>Telephone</td>
<td>$_POST[telephone]</td></tr>
<tr>
<td>ADDRESS</td>
<td>$_POST[address]</td></tr>
<tr>
<td>Deliver or Pickup</td>
<td>$_POST[delivery]</td></tr>
<tr>
<td>Camper Tank</td>
<td>$_POST[tank_size]</td></tr>
[16-Sep-14 5:31:48 PM] VIKRANT SHARMA: </thead>
</table>";
$pdf->WriteHTML($strContent);
$pdf->Output('Plastic-data.pdf','D');
echo "PDF file is generated successfully!";
?>
#1
0
by changing libraries name i got the answer.
hope yhis will help you to.
<?php
require('htmlFPDF/html2fpdf.php');
$pdf=new HTML2FPDF();
$pdf->AddPage();
$fp = fopen("sample.html","r");
$strContent = "<table style='width:100%; border=1px solid black;padding:5px;'>
<thead>
<tr>
<td><h1 style='text-align:center'><b>Your submitted data is</b></h1></td>
</tr>
<tr>
<td>Name</td>
<td>$_POST[name]</td></tr>
<tr>
<td>Email</td>
<td>$_POST[email]</td></tr>
<tr>
<td>Telephone</td>
<td>$_POST[telephone]</td></tr>
<tr>
<td>ADDRESS</td>
<td>$_POST[address]</td></tr>
<tr>
<td>Deliver or Pickup</td>
<td>$_POST[delivery]</td></tr>
<tr>
<td>Camper Tank</td>
<td>$_POST[tank_size]</td></tr>
[16-Sep-14 5:31:48 PM] VIKRANT SHARMA: </thead>
</table>";
$pdf->WriteHTML($strContent);
$pdf->Output('Plastic-data.pdf','D');
echo "PDF file is generated successfully!";
?>