Jump to content

Convert table to PDF


cheechm

Recommended Posts

Hi,

I tried using TCPDF but can't seem to make it work. Here is the code I am trying to convert to a PDF:

 

  $qpdftext = "<table border=\"0\" cellspacing=\"4\" cellpadding=\"4\" width=\"80%\" valign=\"top\">
<tr><td colspan=\"20\" bgcolor=\"#CCC\">Quote</td></tr>
<tr><td>Quote# " . $qid . "</td></tr>
<tr><td>Tel# 81</td></tr>
                <tr><td>Customer Name: Nick</td></tr>
                
                
                
<tr><td colspan=\"20\"> </td></tr>
<tr bgcolor=\"#CCC\"><td colspan=\"2\">Item ID</td><td colspan=\"2\">Quantity</td><td colspan=\"12\">Item</td><td 

colspan=\"2\">Each</td><td colspan=\"2\">Cost</td></tr>";
            $num_rows = $_POST['num'];
            $i = 0;
            while ($i < $num_rows) {

                ${'name' . $i} = $_POST['name' . $i];
                $cost = $_POST[${'name' . $i}];
                $id = $_POST['id' . $i];
                $quantity = $_POST['quantity' . $i];
                $costa[] = $_POST[${'name' . $i}];
                $icost = number_format($_POST['o' . ${'name' . $i}], 2);
                $discounts[] = $quote->get_discount($icost, $cost);
                $percentages[] = $quote->percentages;

                $qpdftext .= "<tr><td colspan=\"2\">" . $_POST['id' . $i] . "</td><td colspan=\"2\">" .
                    $_POST['quantity' . $i] . "</td><td colspan=\"12\">" . $_POST['name' . $i] .
                    "</td><td colspan=\"2\">£" . number_format($_POST['each' . ${'name' . $i}], 2) .
                    "</td><td colspan=\"2\">£" . number_format($_POST[${'name' . $i}], 2) .
                    "</td></tr>";


                $sql = "UPDATE quote_items SET cost = " . $cost . " WHERE item = " . $id .
                    " AND qid = " . $qid . "";
                $i++;
                $result = db_query($sql) or die("MySQL ERROR: " . mysql_error());
            }


            $delivery = $_POST['delivery'];
            if ($delivery) {
                $del = "delivery = " . $delivery . ", ";

                $delivery = "<tr><td colspan=\"16\"></td><td colspan=\"2\">Delivery</td><td colspan=\"2\">£" .
                    number_format($_POST['delivery'], 2) . "</td></tr>";
                $deli = number_format($_POST['delivery'], 2);
            } else {
                $delivery = "";
            }
            if ($result) {
                $sql = "UPDATE quote SET " . $del . " status = 3 WHERE qid = " . $qid . "";
                $result = db_query($sql) or die("MySQL ERROR: " . mysql_error());
            }

            $sql = "SELECT * FROM customers WHERE cid = " . $_POST['cid'] . "";
            $result = db_query($sql) or die("MySQL ERROR: " . mysql_error());
            while ($row = db_fetch_array($result)) {
            }

            $percentage = array_sum($percentages);
            $totalcost = array_sum($costa);
            $discount = array_sum($discounts);
            $exvat = $totalcost + $deli - $dis;
            $incvat = ($exvat * 1.175) - $exvat;
            $overall = $incvat + $exvat;
            if ($discount == 0) {
                $discount = "";
            } else {
                $discount = "<tr><td colspan=\"16\"></td><td colspan=\"2\">Discount</td><td colspan=\"2\">£" .
                    number_format($discount, 2) . " / " . floor($percentage / $num_rows) .
                    "%</td></tr>";
            }
            $qpdftext .= "<tr><td colspan=\"20\"> </td></tr><tr><td colspan=\"16\"></td><td colspan=\"2\" 

bgcolor=\"#CCC\">Subtotal</td>
		<td colspan=\"2\" bgcolor=\"#CCC\">£" . number_format($totalcost, 2) .
                "</td></tr>
                " . $discount . "
" . $delivery . "
<tr><td colspan=\"16\"></td><td colspan=\"2\">Total Ex. Vat</td><td colspan=\"2\">£" .
                number_format($exvat, 2) . "</td></tr>
<tr><td colspan=\"16\"></td><td colspan=\"2\">Vat @ 17.5%</td><td colspan=\"2\">£" .
                number_format($incvat, 2) . "</td></tr>
<tr><td colspan=\"16\"></td><td colspan=\"2\" bgcolor=\"#CCC\">Total</td><td colspan=\"2\" bgcolor=\"#CCC\">£" .
                number_format($overall, 2) . "</td></tr>
</table>";


 

 

When the PDF is saved, all you can see is the HTML source code.  ???

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/123180-convert-table-to-pdf/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.