Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将本地主机PHP转换为PDF_Php_Html_Mysql_Pdf Generation - Fatal编程技术网

将本地主机PHP转换为PDF

将本地主机PHP转换为PDF,php,html,mysql,pdf-generation,Php,Html,Mysql,Pdf Generation,我目前有一个主页,其中设置了一个表,包括用于获取表行数据的数组查询,我测试了PhpToPDF和TCPDF,但遇到了我不知道该做什么的问题,我的数组限制了我发送数据访问的选项,但数组依赖于用户登录时,他们的登录用户名为查询提供从数据库获取所需的信息条件。我还谈到了网页在localhost上托管的问题。有人可以演示在单击“创建pdf”时如何将表格转换为pdf文档吗?可预制自由解 $query = "select * from orders where userid= ' $userid' order

我目前有一个主页,其中设置了一个表,包括用于获取表行数据的数组查询,我测试了PhpToPDF和TCPDF,但遇到了我不知道该做什么的问题,我的数组限制了我发送数据访问的选项,但数组依赖于用户登录时,他们的登录用户名为查询提供从数据库获取所需的信息条件。我还谈到了网页在localhost上托管的问题。有人可以演示在单击“创建pdf”时如何将表格转换为pdf文档吗?可预制自由解

$query = "select * from orders where userid= ' $userid' order by orderid";

$result = mysqli_query($db,$query);
if ($result){
    while ($rows = mysqli_fetch_array($result))
    {
?>

<tr>
     <td> <?php echo $rows[4]; ?> </td>
     <td> <?php echo $rows[0]; ?>  </td>
     <td> <?php echo $rows[1]; ?> </td>
     <td> <?php echo $rows[2]; ?>  </td>
     <td> <?php echo $rows[3]; ?> </td>                       
     <td>
      <a href ="deleteorderhomepage.php?receiptid=<?php echo $rows[3]?>&orderid=<?php echo $rows[0]?>">Delete </a>
     </td>
</tr>
<?php
    if(isset($_POST["create_pdf"])) {  }
        }
    }
 ?

</table>
    </br>
        <input type="submit" name="create_pdf"  value="Create PDF" />                
    </div>
    </div>             
</body>
</html>

通常使用以下库之一:

这是一个来自TCPDF库和链接的示例:


您可以使用这个非常简单的插件:Datatables


如果您只是想将html表转换为pdf,最好使用datatables[@LahiruTM我该怎么做呢?我想查一个教程很简单,你只需回叫到你的页面,你也可以使用基于javascript的工具,但我认为这些工具不太好用。@到达顶点以我下面的答案为例。这是一个非常简单的客户端插件。你可以从PHP生成表并添加这些副本,Excel、Pdf和使用Datatables插件从客户端打印。不仅如此,您还可以拥有更多的功能,如排序和顺序…eek mysql_查询?您可以在任何PHP框架上使用自己的查询。呃,致命错误:未捕获的异常“exception”,带有消息“FPDF错误:某些数据已经输出,无法发送Pdf文件”C:\wamp64\www\NaturesZone\pages\fpdf181\fpdf.php第271行!异常:fpdf错误:一些数据已经输出,无法在线发送C:\wamp64\www\NaturesZone\pages\fpdf181\fpdf.php中的PDF文件。我能使用mysqli_查询获取行吗?我需要一个PDF格式的动态表,因为每个用户都有一个或多个订单,就像在examp中一样该表由默认值填充。您可以动态生成该表,唯一的事情是向JavaScript部分中指定的表添加相同的id。嘿,很抱歉,响应太晚了。我尝试使用此演示并在mysqli_查询中添加了php行,但在生成该表时,预期结果是错误的是生成的,但是当使用按钮Print/Copy/PDF时,只有第一行被应用。我通过混淆abit得到了解决方案,和标记限制了获取被插件读取。这意味着当我删除两个标记并让它按预期工作时。非常感谢
require('fpdf17/fpdf.php');
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',10);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('times','B',10);
$pdf->Cell(25,7,"Stud ID");
$pdf->Cell(30,7,"Student Name");
$pdf->Cell(40,7,"Address");
$pdf->Cell(30,7,"Class");
$pdf->Cell(30,7,"Phone No");
$pdf->Cell(30,7,"E-mail");
$pdf->Ln();
$pdf->Cell(450,7,"----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
$pdf->Ln();

        include ('db.php');
        $sql = "SELECT studid,name,address,class,phone,email FROM studinfo";
        $result = mysql_query($sql);

        while($rows=mysql_fetch_array($result))
        {
            $studid = $rows[0];
            $name = $rows[1];
            $address = $rows[2];
            $class = $rows[3];
            $phone = $rows[4];
            $email = $rows[5];
            $pdf->Cell(25,7,$studid);
            $pdf->Cell(30,7,$name);
            $pdf->Cell(40,7,$address);
            $pdf->Cell(30,7,$class);
            $pdf->Cell(30,7,$phone);
            $pdf->Cell(30,7,$email); 
            $pdf->Ln(); 
        }
$pdf->Output();
<html>
<head>
<title>Datatables Exmple by LahiruTM</title>

<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet"/>
<link href="https://cdn.datatables.net/buttons/1.5.2/css/buttons.dataTables.min.css" rel="stylesheet"/>


<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.flash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js"></script>


<script>
$(document).ready(function() {
    $('#example').DataTable( {
    dom: 'Bfrtip',
    buttons: [
        { extend:'copy', attr: { id: 'allan' } }, 'csv', 'excel', 'pdf', 'print'
    ]
    } );
} );
</script>
</head>
<body>
<table id="example" class="display" style="width:100%">
    <thead>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Tiger Nixon</td>
            <td>System Architect</td>
            <td>Edinburgh</td>
            <td>61</td>
            <td>2011/04/25</td>
            <td>$320,800</td>
        </tr>
        <tr>
            <td>Garrett Winters</td>
            <td>Accountant</td>
            <td>Tokyo</td>
            <td>63</td>
            <td>2011/07/25</td>
            <td>$170,750</td>
        </tr>
        <tr>
            <td>Ashton Cox</td>
            <td>Junior Technical Author</td>
            <td>San Francisco</td>
            <td>66</td>
            <td>2009/01/12</td>
            <td>$86,000</td>
        </tr>
        <tr>
            <td>Cedric Kelly</td>
            <td>Senior Javascript Developer</td>
            <td>Edinburgh</td>
            <td>22</td>
            <td>2012/03/29</td>
            <td>$433,060</td>
        </tr>
        <tr>
            <td>Airi Satou</td>
            <td>Accountant</td>
            <td>Tokyo</td>
            <td>33</td>
            <td>2008/11/28</td>
            <td>$162,700</td>
        </tr>
        <tr>
            <td>Brielle Williamson</td>
            <td>Integration Specialist</td>
            <td>New York</td>
            <td>61</td>
            <td>2012/12/02</td>
            <td>$372,000</td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </tfoot>
    </table>
</body>
</html>