Please Help me. I am coding PHP using below code but out put is not perfect. i am also attach output picture below.


require_once 'core.php';
$pdf = new FPDF();

$orderId = $_POST['orderId'];

$sql = "SELECT orders.order_id, orders.order_date, customer.customer_name, customer.customer_mobile, orders.sub_total, orders.vat, orders.total_amount,, orders.grand_total, orders.paid, orders.due, orders.payment_place,orders.gstn FROM orders INNER JOIN customer ON customer.customer_id = orders.client_name WHERE orders.order_id = $orderId";

$orderResult = $connect->query($sql);
$orderData = $orderResult->fetch_array();

$orderNo = $orderData[0];
$orderDate = $orderData[1];
$clientName = $orderData[2];
$clientContact = $orderData[3]; 
$subTotal = $orderData[4];
$vat = $orderData[5];
$totalAmount = $orderData[6]; 
$discount = $orderData[7];
$grandTotal = $orderData[8];
$paid = $orderData[9];
$due = $orderData[10];
$payment_place = $orderData[11];
$gstn = $orderData[12];

if ($orderDate && $orderNo) {


  $pdf->Cell(50,10,": ".$orderDate,0,1);
  $pdf->Cell(50,10,"Customer Name",0,0);
  $pdf->Cell(50,10,": ".$clientName,0,1);


  $pdf->Cell(70,10,"Product Name",1,0,"C");
  $pdf->Cell(40,10,"Total (Tk)",1,1,"C");

$orderItemSql = "SELECT order_item.product_id, order_item.rate, order_item.quantity,,
product.product_name FROM order_item
   INNER JOIN product ON order_item.product_id = product.product_id 
 WHERE order_item.order_id = $orderId";
$orderItemResult = $connect->query($orderItemSql);
$row = $orderItemResult->fetch_array(); 

for ($i=1; $i < count($row[0]) ; $i++) { 
    $pdf->Cell(10,10, ($i+1) ,1,0,"C");
    $pdf->Cell(70,10, $row[4][$i],1,0,"C");
    $pdf->Cell(30,10, $row[2][$i],1,0,"C");
    $pdf->Cell(40,10, $row[1][$i],1,0,"C");
    $pdf->Cell(40,10, ($row[2][$i] * $row[1][$i]) ,1,1,"C");


  $pdf->Cell(50,10,"Sub Total",0,0);
  $pdf->Cell(50,10,": ".$subTotal,0,1);
  $pdf->Cell(50,10,"Gst Tax",0,0);
  $pdf->Cell(50,10,": ".$vat,0,1);
  $pdf->Cell(50,10,": ".$discount,0,1);
  $pdf->Cell(50,10,"Net Total",0,0);
  $pdf->Cell(50,10,": ".$grandTotal,0,1);
  $pdf->Cell(50,10,": ".$paid,0,1);
  $pdf->Cell(50,10,"Due Amount",0,0);
  $pdf->Cell(50,10,": ".$due,0,1);
  $pdf->Cell(50,10,"Payment Type",0,0);
  $pdf->Cell(50,10,": ".$payment_place,0,1);




Output :


So Please Please as early as possible.

Recommended Answers

All 3 Replies

It looks like you're outputting a binary string (a PDF, perhaps?) but you're not setting the proper HTTP header.

What happens if, right above line 81 in the code above, where you call Output(), you do: header('Content-Type: application/pdf');

commented: Thanks for reply , after using -header('Content-Type: application/pdf'); result is same . madam what can i do. +0

I can't see how that would be the case, hmm. Can you take a screenshot of what it looks like now, with the Content-Type header specified?

Can you also please provide your updated code. I want to make sure you added the line properly. Did you make sure there's a space after Content-Type:?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.