2017-02-22 2 views
0

현재 MySql의 정보를 가져 와서 해당 정보를 PDF로 변환하고 PHPmailer를 사용하여 이메일로 보내는 송장 스크립트를 작성 중입니다.FPDF & While 루프

내가 붙어있는 부분은 이걸 PDF로 변환하는 방법입니다. 다음 페이지로 orderid를 게시하여 PDF로 변환 할 수있게하고 싶습니다.

아래 도움말을 보려면 아래 스크립트를 첨부하십시오.

<?php 
session_start(); 
    $username = $_SESSION['username']; 
     $con = mysqli_connect('***', '***', '***', '***'); 
    if (!isset($con)) { 
     die("Connection to Aurora System failed."); 
    } 

    $orderid = $_POST['order_id']; 
    ?> 


<!doctype html> 
<html> 
<body class="body page-orderview clearfix"> 
    <div class="element"></div> 
    <p class="text text-1">SMKD Field Force</p> 
<a href="front.php"><img class="image" src="images/smkd_logo.png"></a> 
    <p class="text text-2">Welcome</p> 
    <p class="text text-3">Order <?php echo "$orderid"; ?> 


    <table> 
     <tr> 
    <th>Product Title</th> 
    <th>Nicotine Strength</th> 
    <th>Quantity</th> 
    <th>Price (inc. VAT)</th> 
    </tr> 
    <?php 

    $query = "SELECT `product`, `variant`, `quantity` FROM orders_detail WHERE order_id = '$orderid'"; 
    $result = mysqli_query($con, $query); 
    $quantitytotal = 0; 
    $quantityline = - 0; 
    while ($row = mysqli_fetch_assoc($result)) { 
     $product = $row['product']; 
     $stuff = $row['quantity']; 
     $variant = $row['variant']; 
     $linequantity = $stuff; 
     $quantitytotal += $stuff; 

     $pricequery = "SELECT product_price FROM products WHERE product_name = '$product'"; 
     $priceresult = mysqli_query($con, $pricequery); 
     $pricetag = 0; 
     $priceline = 0; 
     while ($rowprice = mysqli_fetch_assoc($priceresult)) { 
      $price = $rowprice['product_price']; 
      $pricetag += $price; 
      $priceline = $price; 
     } 
     $linetotal = $priceline * $linequantity; 
     echo '<tr><td>' . $product .' </td> ' . '<td>' . $variant . '</td>' . ' <td> ' . $linequantity . '</td>' . '<td> £' . $linetotal . '</td> </tr>'; 

    } 
    $total = $pricetag * $quantitytotal; 
     ?> 



    <tr><td>Total Ex Vat:</td><td> Total Inc Vat:</td></tr> 

    <tr><td><?php echo "£" . ($total/1.2);?></td> 
    <td><?php echo "£" . $total; ?></td></tr> 
</table> 
</p><br> 
<form method="post" action"pdfinvoice.php"> 
<input type="hidden" value="<?php echo $orderid; ?>" name="orderid"> 
</form> 
Submit button goes here 
</body> 
</html> 

전체 페이지를 PDF로 변환하는 것에 반대하지 않지만 FPDF에서는 가능하지 않습니다.

감사합니다. & 많은 감사!

+0

https://github.com/mpdf/mpdf –

답변

0

스타일링 및 html 요소가 너무 복잡하지 않은 한 https://github.com/dompdf/dompdf을 살펴 보길 권합니다.이 도구는 매우 강력한 HTML to PDF 변환기 라이브러리이며 상당히 많은 HTML을 지원합니다. 그래서 사람들을 포함하지 않는 등이 PDF의 내부 작동하지 않을 수 있습니다

그냥 양식과, (그들은 또는 렌더링되지 않을 수있다는 정확한 HTML 태그에 따라 달라집니다.) 다만 실제로

0

I 몇 주 전에 같은 일을 마쳤습니다. 그러나 내 페이지에는 pdf가 표시되지 않습니다. 체크 아웃이 완료되면 페이지에 성공 메시지가 표시되고 pdf를 사용자에게 전자 메일로 보냅니다.

일단 다운로드하여 FPDF 라이브러리를 PHP 파일에 포함하십시오. FPDF 오브젝트를 생성하여 추가하고 출력하는 것만 큼 문제가됩니다.

require "Resources/PDF/fpdf.php"; 

    $pdf = new FPDF(); 
    $pdf->SetAutoPageBreak(true, 0); 
    $pdf->SetLeftMargin(8); 
    $pdf->AddPage(); 
    $pdf->SetFont('Arial','B',20); 
    $pdf->SetTextColor(255); 
    $pdf->SetFillColor(0,153,204); 
    $pdf->Cell(194,10,'MyCompany Inc.','LRT',0,'L', true); 
    $pdf->Ln(); 
    $pdf->SetFont('Arial','I',12); 
    $pdf->Cell(97,10,'Invoice #: '.$id.''.$cnt.'','LB',0,'L', true); 
    $pdf->Cell(97,10, "Date: ".date("d-m-Y")." ",'RB',0,'R', true); 
    $pdf->Ln(); 
    $pdf->SetTextColor(0,153,204); 
    $pdf->SetFont('Arial','B',14); 
    $pdf->Cell(40,10,'Ship to:',0,4); 
    $pdf->SetTextColor(0,0,0); 
    $pdf->SetFont('Arial','I',12); 
    $pdf->Cell(40,5, $_POST['shippingName'],0,5); 
    $pdf->Cell(40,5, $COMP,0,6); 
    $pdf->Cell(40,5, $EMAIL,0,6); 
    $pdf->Cell(40,5, $_POST['shippingPhoneNumber'],0,7); 
    $pdf->Cell(40,5, $_POST['shippingAddress'],0,8); 
    $pdf->Cell(40,5, $_POST['shippingPostalCode'],0,9); 
    $pdf->Cell(40,5, $_POST['shippingCity'],0,10); 
    $pdf->Cell(40,5, $_POST['shippingProvince'],0,11); 
    $pdf->Cell(40,5, $_POST['shippingCountry'],0,12); 
    $pdf->Output(); //should display the pdf to the page 

출력 ("filepath"); 당신이 그 때 파일을 이메일을 보낼 수 있던 전화 번호부에 pdf를 저장할 수있다. 위 코드는 헤더를 만들고 $ _POST 변수를 통해 전달 된 사용자 정보를 나열합니다.

FPDF 문서는 때때로 도움이 될 수 있습니다. http://www.fpdf.org/