【问题标题】:Show each list item in a different page of the pdf在 pdf 的不同页面中显示每个列表项
【发布时间】:2018-11-25 12:26:01
【问题描述】:

我有这个查询,我使用包“https://github.com/barryvdh/laravel-dompdf”以 pdf 格式显示结果:

public function getRegistrationInfo($regID){
    $registration = Registration::with('conference',Conference.registrationTypes','Conference.registrationTypes.participants')
            ->where('id',$regID)->first();

    $pdf = PDF::loadView('pdf.registration', compact('registration'));

    return $pdf->download('invoice.pdf');
}

在“pdf.registration”视图中我有这个来显示查询结果:

@foreach($registration->conference->registrationTypes as $key=>$registrationType)

        <li>
            <span>show the registration ID here : {{$registration->id}}</span> <br>
            <span>Conference name {{$registration->conference->name}}</span><br>
            <span>Registration type: {{$registration->conference->registrationTypes[$key]['name']}}</span><br>
            <span> Participant: {{$registration->conference->registrationTypes[$key]
            ->participants[0]->name .' '.$registration->
            conference->registrationTypes[$key]->participants[0]->surname}}</span><br>
            <span>Price: {{$registration->conference->registrationTypes[$key]['price']}}</span><br>
        </li>

    @endforeach

当用户单击按钮下载 pdf 时,它会工作。现在它返回 2 个结果、2 个列表项,并且这两个列表项都出现在 pdf 的第一页上。但我想将每个列表项放在 pdf 的一页中。你知道实现这一点需要什么?

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    您可以在页面中使用下面的 html 和 css 来进行分页 -

    把下面的 html 放在你想分页的地方。

    <div class="breakNow"></div>
    

    在您的 css 代码中:

    div.breakNow { page-break-inside:avoid; page-break-after:always; }
    

    在此之后,您的 pdf 也应该在下一页中包含内容。

    【讨论】:

    • 谢谢,但仍然出现在同一页面上:“@foreach($registration->conference->registrationTypes as $key=>$registrationType)
    • .....
    • @endforeach".
  • 在同一页面上添加 css 样式,例如“ div.breakNow { page-break-inside:avoid; page-break-after:always; }... 可以,谢谢!
  • 猜你喜欢
    相关资源
    最近更新 更多
    热门标签