在Symfony 4.2中使用dompdf时生成空白PDF页面

时间:2019-04-10 11:54:18

标签: php laravel symfony symfony4 dompdf

enter image description here我正在使用dompdf从HTML页面生成pdf文件。

控制器:

public function downloadPdfByDriveUserId($_drive, $driveId, $userId, CampusConnectServices\CampusConnectHelper $campusConnectHelper)
    {
        $response = //some array I fetch for helper.

        //Configure Dompdf.
        $pdfOptions = new Options();

        $pdfOptions->set('defaultFont', 'Arial');
        $dompdf = new Dompdf($pdfOptions);
        $html = $this->renderView('download_pdf/index.html.twig', [
            'title' => "Download Admint-Card",
            'response' => $response,

        ]);

        $dompdf->loadHtml($html);
        $dompdf->setPaper('A4', 'portrait');
        $dompdf->render();

        //Output the generated PDF to Browser (force download)
        $dompdf->stream("AdmitCard.pdf", [
            "Attachment" => false,
        ]);
    }

HTML:

{% extends 'base.html.twig' %}

{% block title %}Download Admit-card{% endblock %}

{% block body %}

    <div class="example-wrapper">

        <h1>
            {{ title }}
        </h1>
        <h3>Details:</h3>
        <ul>
            <li>
                Event Date :
                {{ response['eventDate']|date('d/m/Y - H:i:s') }}
            </li>
            {% if ((response['driveStartTime'] is defined)or(response['driveEndTime'] is defined)) %}
                <li>
                    Slot Time :
                    {{ response['driveStartTime']|date('H:i:s') }}
                    -
                    {{ response['driveEndTime']|date('H:i:s') }}
                </li>
            {% endif %}

            <li>Student Name :{{ response.name }}</li>
            <li>Email :{{ response.email }}</li>
            <li>Collage :{{ response['college'] }}</li>
            <li>Contact :{{ response['contactNumber'] }}</li>
            <li>Roll Number :{{ response['rollNumber'] }}</li>

        </ul>
    </div>
{% endblock %}
  

上面的代码生成一个pdf文件,我在其中获取HTML页面   第一页。

生成的PDF文件包含9页,其中8页为空白。 我不想将这8个空白页放入要下载的PDF文件中。 如何设置要添加的页面数?

0 个答案:

没有答案