doutuobao4004 2019-03-03 16:50
浏览 33

将PDF从tcpdf保存到数据库

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);
    }

The Photo of Error1

When I run then it will upload pdf file in the database. I am using PHPmyadmin database. In this code, the Invoice are generated and this pdf I want to upload in the database for the further use. But the error are generated from the Query that I am using. This PDF is generated using the TCPDF. In this, the detail are the come from the database at the run time using the PHP code. Thank You. Please Refer this Question

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法