1
我被這個東西困住了,不知道該怎麼辦。我已經搜索了很多次,並且瞭解了fpdf,html2pdf,tcpdf。PHP + html網頁到pdf
我正在創建一張發票,其中我使用了html和php代碼。我想在pdf中顯示該數據,希望將整個頁面轉換爲pdf並打印並保存。但我不知道是什麼我是新來的,不太瞭解。
已經嘗試了一些代碼,但我只得到HTML文本作爲輸出也希望PHP數據。
代碼: 的index.php
<?php
if(!isset($_POST['submit']))
{
?>
<form method="post" action=''>
<div id="page-wrap">
<textarea id="header" name="text" disabled="disabled">INVOICE</textarea>
<div id="identity">
<textarea name="address" id="address" disabled="disabled" style="background-color:#FFF;color:#000">Address</textarea>
<div id="logo">
<img id="image" src="images/logo.png" alt="logo" /></div>
</div>
<div style="clear:both"></div>
<div id="customer">
<!-- <textarea id="customer-title" disabled="disabled" style="background-color:#FFF;color:#000">Widget Corp.
c/o Steve Widget</textarea>
-->
<table id="meta">
<tr>
<td class="meta-head">Invoice #</td>
<td><textarea>000123</textarea></td>
</tr>
<tr>
<td class="meta-head">Date</td>
<td><textarea id="date"></textarea></td>
</tr>
</table>
</div>
<table id="items">
<tr>
<th>Item</th>
<th>Unit Cost</th>
<th>Quantity</th>
<th>Price</th>
</tr>
<?php
include("./config.php");
$q=0;$u=0;$t=0;$tt=0;$s=0;$v=0;
$sql="SELECT m.order_id,m.table_id,l.item_id,l.order_quantity,i.item_name,i.item_price from order_m m,order_list l,item_list i where m.order_id=l.order_id and l.item_id=i.item_id and table_id=2";
$result=mysqli_query($con,$sql);
while($row=mysqli_fetch_array($result))
{
$q=$q+$row[3];
$u=$u+$row[5];
$t=$t+($row[3]*$row[5]);
?>
<tr class="item-row">
<td class="item-name"><?php echo $row[4]?></td>
<td><?php echo $row[5];?></td>
<td><?php echo $row[3];?></td>
<td><?php echo $row[3]*$row[5];}?></td>
</tr>
<tr>
<td>Total </td>
<td><?php echo $u; ?></td>
<td><?php echo $q;?></td>
<td><?php echo $t;?></td>
</tr>
<?php
$sql1="Select * from tax";
$res=mysqli_query($con,$sql1);
$row1=mysqli_fetch_row($res);
if($row1[0]!=0)
{
$v=($row1[0]*$t)/100;
?>
<tr>
<td> </td>
<td></td>
<td>VAT%</td>
<td><?php echo $row1[0]."%";?></td>
</tr>
<?php
}
else
{
}
if($row1[1]!=0)
{
$s=($row1[1]*$t)/100;
?>
<tr>
<td> </td>
<td></td>
<td>Service Tax.%</td>
<td><?php echo $row1[1]."%";?></td>
</tr>
<?php
}
else
{
}
?>
<tr>
<td></td>
<td></td>
<td>Total</td>
<td><?php $tt=$t+$v+$s; echo round($tt);?></td>
</tr>
</table>
<div id="terms">
<h5>Terms</h5>
<textarea>NET 30 Days. Finance Charge of 1.5% will be made on unpaid balances after 30 days.</textarea>
</div>
</div>
<input type="submit" name="submit" value="Print" />
</form>
<?php
}
else
{
ob_start();
require("html2pdf.php");
$the_file = "./index.php";
$myfile = fopen($the_file, "r") or die("Unable to open file!!!!<br><br><br>");
$homepage = file_get_contents($the_file);
fclose($myfile);
$pdf = new PDF_HTML();
$pdf->AddPage();
$pdf->SetFont('Arial','B',9);
$pdf->WriteHTML($homepage);
$pdf->Output();
ob_end_flush();
exit;
}
?>
它也會渲染php代碼嗎? –
是的,它也會渲染php。 –
出錯:請設置動作屬性路徑。這個錯誤與什麼有關? –