sam*_*toh 6 php pdf dompdf laravel laravel-5.3
我从这里得到:https : //github.com/barryvdh/laravel-dompdf
我的控制器是这样的:
public function listdata()
{
$pdf=PDF::loadView('print_tests.test_pdf');
$pdf->setPaper('L', 'landscape');
return $pdf->stream('test_pdf.pdf');
}
Run Code Online (Sandbox Code Playgroud)
我的观点是这样的:
<table>
<tr>
<th>header1</th>
<th>header2</th>
<th>header3</th>
</tr>
<tr>
<td>content-row-1</td>
<td>content-row-1</td>
<td>content-row-1</td>
</tr>
<tr>
<td>content-row-2</td>
<td>content-row-2</td>
<td>content-row-2</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
我希望每一页都有一个页码
有没有人可以帮助我?
试试这个。
<style>
.pagenum:before {
content: counter(page);
}
</style>
<body>
<span class="pagenum"></span>
<table>
<tr>
<th>header1</th>
<th>header2</th>
<th>header3</th>
</tr>
<tr>
<td>content-row-1</td>
<td>content-row-1</td>
<td>content-row-1</td>
</tr>
<tr>
<td>content-row-2</td>
<td>content-row-2</td>
<td>content-row-2</td>
</tr>
</table>
</body>
Run Code Online (Sandbox Code Playgroud)
例如你可以这样做..
在你的控制器中:
$pdf = app('dompdf.wrapper');
$pdf->getDomPDF()->set_option("enable_php", true);
$data = ['title' => 'Testing Page Number In Body'];
$pdf->loadView('welcomeView', $data);
Run Code Online (Sandbox Code Playgroud)
在你的welcomeView.blade.php
<html>
<body>
<h1> {{ $title }} </h1>
<script type="text/php">
if (isset($pdf)) {
$x = 250;
$y = 10;
$text = "Page {PAGE_NUM} of {PAGE_COUNT}";
$font = null;
$size = 14;
$color = array(255,0,0);
$word_space = 0.0; // default
$char_space = 0.0; // default
$angle = 0.0; // default
$pdf->page_text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
请按照以下步骤来实现它:
-启用DOMPDF_ENABLE_PHP从/config/dompdf.php
-通过发布供应商档案php artisan vendor:publish command
-山口$pdf对象从控制器:
-添加下面的视图文件中的代码:
<script type="text/php">
if ( isset($pdf) ) {
$font = Font_Metrics::get_font("helvetica", "bold");
$pdf->page_text(72, 18, "Header: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));
}
</script>
Run Code Online (Sandbox Code Playgroud)
您可以从页数和页码中获得更多信息
| 归档时间: |
|
| 查看次数: |
11974 次 |
| 最近记录: |