Php 我有一个从下拉菜单中选择的日期创建pdf报告。我不知道该怎么做
因此,我从我的引导模式内的下拉模式中选择一天,当我单击生成pdf按钮时,会显示一条确认成功的消息,但不会生成pdf。当我使用localhost/test4/check\u booking\u day.pdf在浏览器上直接运行该文件时,pdf文件会正确显示。我不知道是什么问题。谁能帮帮我吗。 我的模式代码:Php 我有一个从下拉菜单中选择的日期创建pdf报告。我不知道该怎么做,php,mysql,ajax,bootstrap-modal,tcpdf,Php,Mysql,Ajax,Bootstrap Modal,Tcpdf,因此,我从我的引导模式内的下拉模式中选择一天,当我单击生成pdf按钮时,会显示一条确认成功的消息,但不会生成pdf。当我使用localhost/test4/check\u booking\u day.pdf在浏览器上直接运行该文件时,pdf文件会正确显示。我不知道是什么问题。谁能帮帮我吗。 我的模式代码: <div class="modal fade" id="modal_check_booking_day" tabindex="-1" role="dialog" aria-labelle
<div class="modal fade" id="modal_check_booking_day" tabindex="-1" role="dialog" aria-labelledby="modal_check_booking_day_label" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form method="post" id = "booking_day_form"></form>
<div class="modal-header">
<h5 class="modal-title" id="modal_check_booking_day_label">Check Booking day</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class = "col-md-6">
<div class="form-group">
<!-- <label>Select Day</label> -->
<select id="Day" name = "Day" class="custom-select">
<option value="" disabled selected style="display: none;">Select Day</option>
<?php echo $GroupDay; ?>
</select>
</div>
<div id="response"></div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" name = "booking_day_pdf" id="booking_day_pdf" class="btn btn-primary">Generate PDF</button>
</div>
</div>
</form>
</div>
</div>
用于生成pdf文件的My check_booking_day.php:
<?php
function fetch_data()
{
$output = '';
$connection = new PDO("mysql:host=localhost;dbname=baps", "root", "");
$sql = "SELECT * FROM tab_visitorgroups ORDER BY GroupName";
$statement = $connection->prepare($sql);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
$output .= '<tr>
<td>'.$row["DateVisit"].'</td>
<td>'.$row["TimeVisit"].'</td>
<td>'.$row["GroupName"].'</td>
<td>'.$row["GroupName"].'</td>
<td>'.$row["GroupType"].'</td>
<td>'.$row["TotalVisitors"].'</td>
<td>'.$row["Male"].'</td>
<td>'.$row["Female"].'</td>
<td>'.$row["VisitToMuseum"].'</td>
<td>'.$row["GroupInfo"].'</td>
<td>'.$row["GuideRequired"].'</td>
<td>'.$row["GuideName"].'</td>
<td>'.$row["Status"].'</td>
<td>'.$row["DataInputDate"].'</td>
</tr>
';
}
return $output;
}
if(isset($_POST["booking_day_pdf"]))
{
require_once('tcpdf/tcpdf.php');
$obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$obj_pdf->SetCreator(PDF_CREATOR);
$obj_pdf->SetTitle("Group Visits");
$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('helvetica', '', 8);
$obj_pdf->AddPage();
$content = '';
$content .= '
<h3 align="center">Group Visits</h3><br /><br />
<table border="1" cellspacing="0" cellpadding="5">
<tr>
<th>Date of Visit</th>
<th>Time</th>
<th>Group Name</th>
<th>Contact Name</th>
<th>Group Type</th>
<th>Total Visitors</th>
<th>Male</th>
<th>Female</th>
<th>Museum?</th>
<th>Other Info</th>
<th>Guide Needed</th>
<th>Guide Name</th>
<th>Status of Visit</th>
<th>Data Input Date</th>
</tr>
';
$content .= fetch_data();
$content .= '</table>';
$obj_pdf->writeHTML($content);
ob_end_clean();
$obj_pdf->Output('check-booking-day.pdf', 'I');
}
?>
myindex.php中的按钮
<input class="dropdown-item" type="button" data-toggle="modal" data-target="#modal_check_booking_day" name="check_booking_day" id="check_booking_day" value="Check Booking Day" />
您需要替换$obj_pdf->输出'check-booking-day.pdf','I';使用$obj_pdf->输出'check-booking-day.pdf','D';为了下载该文件,我不想下载它,而是在一个新选项卡中打开它。
<input class="dropdown-item" type="button" data-toggle="modal" data-target="#modal_check_booking_day" name="check_booking_day" id="check_booking_day" value="Check Booking Day" />