【发布时间】:2018-07-25 17:50:11
【问题描述】:
我正在尝试在 Windows 7 64 位上运行的 CodeIgniter 上使用 DOMPDF 版本 0.8 将 HTML 页面呈现为 PDF。我的开发机器在 Windows 10 Pro 上的 XAMPP 上运行 PHP 7,但生产服务器在 Windows 7 Professional 64 位上运行 PHP 5.6。
我意识到,当我在本地计算机上运行应用程序时,一切正常,并且正确生成了 PDF,图像和样式正确显示在适当的位置。但是当我部署到生产机器时,样式和图像不能再次正确渲染。图像不显示,样式不渲染。
如果有任何解决此问题的建议,我将不胜感激
下面是我的部分代码:
//应用程序/库/pdf.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once("./vendor/dompdf/dompdf/src/autoloader.php");
use Dompdf\Dompdf;
class Pdf
{
public function generate($html, $filename='', $stream=TRUE, $paper = 'A4',
$orientation = "landscape")
{
$dompdf = new DOMPDF();
$dompdf->loadHtml($html);
$dompdf->setPaper($paper, $orientation);
$dompdf->render();
if ($stream)
{
$dompdf->stream($filename.".pdf", array("Attachment" => 1));
}
else
{
return $dompdf->output();
}
}
}
//Application/controllers/report.php
...some code removed for brevity
$this->load->library('pdf');
$html=$this->load->view('parts/pdf-head',NULL,true);
$html.=$this->load->view('admin/reports/periodic/pdf',['results'=>$_SESSION['students_result']],true);
$this->pdf->generate($html,'report');
//Application/views/admin/reports/periodic/pdf.php
<?php
if(empty($results))
{
echo "<div class='alert alert-danger'><span class='fa fa-warning'></span> No result found in record for the selected parameters</div>";
}
else
{
foreach($results['scores'] as $student=>$scores)
{
?>
<table class="table table-bordered" style="padding: 10px">
<tr class="tr-row2">
<td colspan="16" style="text-align: center">
<?php echo img(['src'=>"style-resources/logo2.png", 'width'=>"50px"]);?>
</td>
</tr>
<tr class="tr-row2">
<td colspan="16" style="text-align: center">
<?php echo $results['campus'];?>
</td>
</tr>
<tr class="tr-row2">
<td colspan="16" style="text-align: center">
<?php echo $results['title'];?>
</td>
</tr>
<tr class="tr-row2">
<th colspan="10" style="text-align: left;">
<?php echo strtoupper($scores['student_info']['student_names']);?>
</th>
<td colspan="6">
<?php echo $scores['student_info']['class'].', '.$scores['student_info']['class_arm']; ?>
</td>
</tr>
<tr class="tr-row2">
<td colspan="7" style="text-align: right">Number of class contacts </td><td style="text-align: left"><?php echo $scores['student_info']['attendance'];?></td><td colspan="7" style="text-align: right">Student's Attendance</td><td style="text-align: left"><?php echo $scores['attendance_score'];?></td>
</tr>
<tr class="tr-row2">
<th>C.A.1 (10%)</th><td><?php echo $scores['ca1']; ?></td><th>C.A.2 (10%)</th><td><?php echo $scores['ca2']; ?></td><th>Classwork (15%)</th><td><?php echo $scores['classwork']; ?></td><th> Attendance (5%)</th><td><?php echo $scores['attendance_score'];?></td><th>EXAM (60%)</th><td><?php echo $scores['exam']; ?></td><th>TOTAL (100%)</th><td><?php echo $scores['total'];
?></td><th>Grade</th><td><?php echo $scores['grade']; ?></td><th>POSITION</th><td><?php $this->load->helper('ordinalize'); echo ordinalize(array_search($scores['total'],$_SESSION['result_total'])+1); ?></td>
</tr>
<tr class="tr-row2">
<th colspan="3">Highest Score</th><td><?php echo max($_SESSION['result_total']); ?></td><th>Lowest Score</th><td><?php echo min($_SESSION['result_total']); ?></td><th>Class Average</th><td><?php echo array_sum($_SESSION['result_total'])/count($_SESSION['students_result']['scores']) ?></td><th colspan="3">Effort</th><td colspan="5" style="text-align: left"><?php echo $scores['effort'];?> </td>
</tr>
<tr>
<th colspan="6">
<table class="table table-striped table-bordered">
<tr class="tr-row2">
<td colspan="2" style="text-align: center">
Accomplishments for the Term
</td>
</tr>
<tr class="tr-row2">
<th>Exercise/Activity</th>
<th>Score</th>
</tr>
<?php
if(empty($scores['scores'][1]))
{
echo "<tr class='tr-row2'><td colspan='2'><em> No lesson exercise found for this student</em></td></tr>";
}
else {
foreach ($scores['scores'][1] as $a => $b) {
if ($a != 'total') {
echo "<tr class='tr-row2'><th>" . $a . "</th><td>" . $b . "</td></tr>"; ?>
<?php }
}
}
?>
<tr class="tr-row2"><th colspan="2" style="text-align: center">Summary of report</th></tr>
<tr class="tr-row2">
<td colspan="2"><em><?php echo $scores['comment']; ?></em></td>
</tr>
</table>
</th>
<th colspan="10">
<table class="table table-striped">
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
Skills/Strengths demonstrated
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
<em><?php echo $scores['student_info']['skills'];?></em>
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
Observed Weakness(es)
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: Left">
<em><?php echo $scores['student_info']['weaknesses'];?></em>
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
Remedial steps taken
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
<em><?php echo $scores['student_info']['remedies'];?></em>
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
Further improvement steps to be taken
</td>
</tr>
<tr class="tr-row2">
<td colspan="2" style="text-align: left">
<em><?php echo $scores['student_info']['further_actions'];?></em>
</td>
</tr>
</table>
</th>
</tr>
<tr class="tr-row2">
<th colspan="4" style="text-align: right">Educator's Name</th><td colspan="4" style="text-align: left"><em><?php echo $results['educator']; ?></em></td><th colspan="4" style="text-align: right">Educator's Signature</th><td colspan="4"></td>
</tr>
<tr class="tr-row2">
<th colspan="4" style="text-align: right">Coordinator's Name</th><td colspan="4" style="text-align: left"><em><?php echo $results['coordinator'];?></em></td><th colspan="4" style="text-align: right">Coordinator's Signature</th><td colspan="4"></td>
</tr>
</table>
<?php }
}
【问题讨论】:
-
您在哪台服务器上托管您的网站(Apache 或 IIS)?
-
@Ganesh Aher 两台机器都在 Apache 上运行。我实际上在两台机器上都使用 XAMPP
-
检查你的配置文件中的 base_url 和 .htaccess 文件
-
@Ganesh Aher 请解释一下。哪个配置文件以及 base_url 和 .htaccess 应该是什么样的?
标签: php windows windows-7 codeigniter-3 dompdf