2014-09-15 3 views
0

HTML 양식의 데이터를 PDF 문서로 쓰고 싶습니다.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

문제 나 질문이있다 : 여기 내 코드는? –

+0

문제는 입니다. 데이터를 PDF로 저장할 수 없습니다 –

+0

이것을 수행하려고하면 어떤 오류가 발생합니까? – APerson

답변

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!"; 
?> 
관련 문제