require_once('tcpdf/tcpdf.php');
$conn=mysqli_connect("localhost","root","","courier_system");
$uname='Honey';
$con_id=2;
$obj_pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$obj_pdf->SetCreator(PDF_CREATOR);
$obj_pdf->SetTitle("Consignment Receipt");
$obj_pdf->SetHeaderData('', '', PDF_HEADER_TITLE, PDF_HEADER_STRING);
$obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$obj_pdf->SetDefaultMonospacedFont('helvetica');
$obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$obj_pdf->SetMargins(PDF_MARGIN_LEFT, '5', PDF_MARGIN_RIGHT);
$obj_pdf->setPrintHeader(false);
$obj_pdf->setPrintFooter(false);
$obj_pdf->SetAutoPageBreak(TRUE, 10);
$obj_pdf->SetFont('times', '', 14);
$obj_pdf->AddPage();
$cotent='
<div style="text-align:right;">
<img width="100px" height="70px" src="images/logo.jpeg"></img>
<h1 align="centre" style="color:blue;">Receipt</h1>
<br/></div>
<hr size="5px">';
$obj_pdf->writeHTML($cotent);
$cotent='<table width="100%">
<tr>
<th width="50%">Order Date</th>
<th width="50%">Order ID</th>
</tr>';
$cotent.=fetch_data($uname,$cid);
$cotent.='</table>';
$obj_pdf->writeHTML($cotent);
$connect = mysqli_connect("localhost", "root", "", "courier_system");
$sql = "SELECT * FROM consignment where user_name='$uname' and con_id=$cid";
$result = mysqli_query($connect, $sql);
$row=mysqli_fetch_assoc($result);
$id=$row['branch_sou_id'];
$cotent='<table width="100%">
<tr>
<th width="50%">Branch Address:</th>
</tr>';
$cotent.=fetch_data1($id);
$cotent.='</table><br/><br/><br/><br/>';
$obj_pdf->writeHTML($cotent);
$cotent='<table width="100%">
<tr>
<th width="50%">From:</th>
<th width="50%">To:</th>
</tr>';
$cotent.=fetch_data2($uname,$cid);
$cotent.='</table><br/><br/><br/><br/>';
$obj_pdf->writeHTML($cotent);
$obj_pdf->SetFont('times', '', 10);
$cotent='
<table border="1" cellspacing="0" cellpadding="5">
<tr>
<th width="10%">Sou Pincode</th>
<th width="10%">Des Pincode</th>
<th width="13%">Pickup Date</th>
<th width="10%">Weight</th>
<th width="10%">Mode</th>
<th width="12%">Texable Value</th>
<th width="14%">IGST</th>
<th width="20%">Total</th>
</tr>';
$cotent.=fetch_data3($uname,$cid);
$cotent.='</table><br/><br/><br/><br/>';
$obj_pdf->writeHTML($cotent);
$obj_pdf->SetFont('times', '', 14);
$tax=0.12*$row['price'];
$total=floor(0.5+$tax+$row['price']);
$cotent='Total Price is Rs.'. $total;
$obj_pdf->writeHTML($cotent);
$cotent='The Price in Word '. getIndianCurrency($tax+$row['price']);
$obj_pdf->writeHTML($cotent);
$cotent='
<div style="text-align:right;">
<p style="font-size:16px">Signature</p>
<img width="100px" height="70px" src="images/Signa.jpg"></img>
</div>';
$obj_pdf->writeHTML($cotent);
$content=$obj_pdf->Output('', 'S');
//header("Content-type:application/pdf");
//header("Content-Disposition:attachment;filename=pdf.pdf");
//header("Location:abc.php?str='$sontent'");
echo $content."<br/><br/><br/><br/>";
// $data=file_get_contents('pdf.pdf');
// echo $data;
$sql="update consignment set receipt='$content' where con_id=4";
if(mysqli_query($connect,$sql))
{
echo "hiiii";
}
else {
echo "Error";
echo mysqli_error($connect);
}
错误图片1
当我运行时,它将在数据库中上传pdf文件。 我正在使用PHPmyadmin数据库。 在此代码中,生成了发票,并且我想将此pdf上载到数据库中以供进一步使用。 但是错误是由我正在使用的查询生成的。 此PDF是使用TCPDF生成的。 在此,详细信息是在运行时使用PHP代码来自数据库的。 谢谢。 Please Refer this Question