gpt4 book ai didi

php - 创建 PDF 时未应用 dompdf 横向 View

转载 作者:行者123 更新时间:2023-12-04 10:45:21 24 4
gpt4 key购买 nike

我想使用 DOMPDF 创建报告。我的 pdf 已成功创建,但问题是我想以横向打印它。我给出了选项 $pdf->setPaper('A4', 'landscape');//set page size andorientation 但它仍然显示纵向 View 。我该如何解决这个问题?

<?php


if(isset($_GET["action"]))
{
include('database_connection.php');
require_once 'pdf.php';
session_start();

if($_GET["action"] == "leave_apply_report")
{
if(isset($_GET["month"],$_GET["department"]))
{
$pdf = new Pdf();
$currentMonth= date('Y-m');
$passmonth= $_GET["month"];

if($currentMonth == $passmonth){
$strat = date('Y-m-01');
$end = date('Y-m-d');
}
else{
$strat = date('Y-m-01', strtotime($passmonth));
$end = date('Y-m-t', strtotime($passmonth));
}
$query01 ="SELECT *
FROM department
WHERE dept_Id ='".$_GET["department"]."'";
$statement = $connect->prepare($query01);

if($statement->execute())
{

$result = $statement->fetchAll();
foreach($result as $row){
$header = '<table width="100%" border= 0>';
$header.='<tr><td style="width:50%"><b>Deprtment :</b><font size="1"><span> &nbsp;'. $row["dept_Name"] .'</span></font></td>
<td style="width:17%"><b>Period :</b><font size="1"><span><span> &nbsp;'.$strat.' - '.$end.'</span><span></font></td></tr>' ;
$header .= '</table>';
}
}

$query ="SELECT DISTINCT(emp_id),emp_name,Designation,Department,Section,shift_Id FROM nonacadamic
INNER JOIN department
ON department.dept_Name = nonacadamic.Department
WHERE dept_Id = '".$_GET["department"]."'";

$statement = $connect->prepare($query);
if($statement->execute())
{
$result = $statement->fetchAll();
$headerfix = '<div class="body">
<b>University Of Kelaniya &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Course Overtime approval month Report</b><br><br>';


$table = '<style>
@page { margin: 20px 30px 40px 50px; }
#table { border: 1px solid black;
font-family: arial, sans-serif;}
</style>';
$table .='<table width="100%" border="1" cellpadding="3" cellspacing="0" id="table">';
$table .='<tr><th style="text-align: center;width:10%;"><font size="1">Employee Number</font></th><th style="text-align: center;width:30%;"><font size="1">Employee Name</font></th><th style="text-align: center;width:40%;"><font size="1">Designation</font></th><th style="text-align: center;width:10%;"><font size="1">Approved OT</font></th><th style="text-align: center;"><font size="1">Pending OT</font></th></tr>';


foreach($result as $row)
{

$table .='<tr>';
$table .='<td style="text-align: center;"><font size="1">' . $row["emp_id"] . '</font></td>';
$table .='<td ><font size="1">' . $row["emp_name"] . '</font></td>';
$table .='<td ><font size="1">' . $row["Designation"] . '</font></td>';
$table .='<td ><font size="1">' . ' ' . '</font></td>';
$table .='<td style="text-align: center;"><font size="1">' . ' ' . ' </font></td>';
$table .='</tr>';

}

$table .='</table>';

}
$footer = '<style>
#footer { position: fixed; right: 0px; bottom: 10px; text-align: center;border-top: 1px solid black;}
#footer .page:after { content: counter(page, decimal); }
</style>
<div id="footer">
<p class="page">Page </p>
</div>';
$query01 ="SELECT *
FROM department
WHERE dept_Id ='".$_GET["department"]."'";
$statement = $connect->prepare($query01);

if($statement->execute())
{

$result = $statement->fetchAll();
foreach($result as $row){
$department= $row["dept_Name"];

$file_name = $department.' Course Overtime Approval Report';
$pdf->loadHtml($headerfix.$header.'<br>'.$table.$footer);//echo $output;
$pdf->set_option("isPhpEnabled", true);
$pdf->render();////Render the HTML as PDF
$pdf->setPaper('A4', 'landscape');//set page size and orientation
ob_end_clean();//fix the pdf unsupported problem
$pdf->stream($file_name, array("Attachment" => false));
exit(0);
}
}
}
}
}

这是我已经尝试过的代码。这个工作发现但唯一的问题是以纵向方式创建报告。

最佳答案

渲染前需要设置纸张尺寸。在调用渲染之后,dompdf 已经完成了将 HTML 渲染为 PDF 的大部分繁重工作。

 $pdf->setPaper('A4', 'landscape');//set page size and orientation

该行应该放在

之前
$pdf->render();////Render the HTML as PDF

关于php - 创建 PDF 时未应用 dompdf 横向 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59731458/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com