我正在使用laravel-snappy&amp; wkhtmltopdf 0.12.2.4(未修补的qt),它不支持<div class="container">
<div class="header">
<img src="{{URL ('/images/logo.png')}}" alt="logo" width="125" height="50"/>
<h2>Parts Orientation</h2>
</div>
<div class="row marginBody">
@foreach ($parts as $part)
<div class="col-xs-2 marginThumbnail">
<div class="border text-center">
<img class="img" src="data:image/jpeg;base64, {{$part->image}}"
alt="Error" width="120" height="120"/>
<p class="displayText {{$part->class}}">
{{$part->name}}
</p>
</div>
</div>
@endforeach
<div class="footer">
<p> {{$date}} </p>
</div>
</div>
</div>
</body>
</html>
开关所以我必须手动创建一个标题,但问题是页眉和页脚只出现在第一页上。是否可以在不升级或降级wkhtmltopdf的情况下为每个页面添加页眉和页脚?
HTML
public function printPDF(Request $request)
{
$parts = Parts::all();
$date = $this->getTime();
$pdf = SnappyPdf::loadView('parts.print.landscape', ["parts" => $parts, "date" => $date->toFormattedDateString()])
->setOrientation('landscape')
->setPaper('a4');
}
}
控制器
#include <iostream>
#include <typeinfo>
#include <cxxabi.h>
template<int ...> struct u_list {};
template<char ...> struct c_list {};
template<int, char > struct foo {};
template<typename...> struct type_list {};
答案 0 :(得分:0)
我能够找到适合我的解决方案。它非常混乱,但它的工作原理
控制器
public function printPDF(Request $request)
{
$parts = Parts::all();
$date = $this->getTime();
// divide by 36 because I can fit 36 items on each page
$totalPages = ceil(count($parts)/36);
$pdf = SnappyPdf::loadView('parts.print.landscape', ["parts" => $parts, "date" => $date->toFormattedDateString(), "totalPages" => $totalPages])
->setOrientation('landscape')
->setPaper('a4');
}
}
HTML
<body>
@php
$count = 0;
$page = 0;
@endphp
<div class="container">
<div class="header">
<img src="{{URL ('/img/logo.png')}}" alt="logo" width="125" height="50"/>
<h2>PARTS ORIENTATION</h2>
</div>
<div class="row marginBody">
@foreach ($parts as $part)
@php
// 36 is the total number of items I can fit on a page
// so after 36 I add a header and footer
if ($count === 36) {
echo '<div class = "newPageHeader">';
echo '<h2>PARTS ORIENTATION</h2>';
echo '</div>';
$count = 0;
$page++;
}
@endphp
<div class="col-xs-2 outline">
<div class="border text-center">
<img class="img" src="data:image/jpeg;base64, {{$part->image}}"
alt="Error" width="127" height="127"/>
<p class="displayText {{$part->c,ass}}">
{{$part->text}}
</p>
</div>
</div>
@php
$count++;
if ($count == 36) {
// 36 is the total number of items I can fit on a page
// so after 36 I add a header and footer
$page = ($page == 0) ? 1 : $page;
echo '<footer class="footer">';
echo "<span class='dateFooter'> $date </span>";
echo "<span class='pageFooter'> $page of $totalPages </span>";
echo '</footer>';
}
elseif ($totalPages == $page) {
echo '<footer class="lastFooter">';
echo "<span class='dateFooter'> $date </span>";
echo "<span class='lastPageFooter'> $page of $totalPages </span>";
echo '</footer>';
}
@endphp
@endforeach
</div>
</div>
</body>