简体   繁体   English

Windows 7,CodeIgniter 3上的DOMPDF样式和图像渲染问题

[英]DOMPDF style and image rendering issue on windows 7, CodeIgniter 3

I am trying to render an HTML page as PDF in using DOMPDF version 0.8 on CodeIgniter running on Windows 7 64 bit. 我试图在Windows 7 64位上运行的CodeIgniter上使用DOMPDF版本0.8将HTML页面呈现为PDF。 My development machine runs PHP 7 on XAMPP on a Windows 10 Pro but the production server runs PHP 5.6 on Windows 7 professional 64bit. 我的开发机器在Windows 10 Pro的XAMPP上运行PHP 7,但生产服务器在Windows 7 Professional 64bit的PHP 5.6上运行。

I realize that when I run the application on my local machine, everything works well and the PDF is properly generated with the images and styles properly displayed in place. 我意识到,当我在本地计算机上运行该应用程序时,一切运行良好,并且PDF正确生成,并且图像和样式正确显示。 But when I deploy to the production machine, the styles and the images dont render properly again. 但是,当我部署到生产机器时,样式和图像无法再次正确渲染。 The images dont display and the styles are not rendered. 图像不显示,样式不呈现。

Please I will appreciate any suggestions to resolve this issue 请解决任何解决此问题的建议

Here are some parts of my codes below: 以下是我的部分代码:

//Application/libraries/pdf.php //Application/libraries/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 //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 //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 }
}

.HTACCESS file looks like this: .HTACCESS文件如下所示:

<IfModule mod_rewrite.c>
  RewriteEngine On

  #RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

in this check your RewriteBase . 在此检查您的RewriteBase

Then Check your application/config/config.php for $config['base_url'] = 'http://localhost/project_name'; 然后检查您的application/config/config.php是否有$config['base_url'] = 'http://localhost/project_name'; line of code. 代码行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM