Created
March 23, 2017 10:14
-
-
Save hidesakai/e75e302f77d4c11206c1c1b3f223d995 to your computer and use it in GitHub Desktop.
Laravel5+laravel-snappyでPDF出力する際のヘッダー・フッター設定とか改ページしたい時のあれこれ ref: http://qiita.com/hidesakai/items/03d755d5da6c7bca0cd5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja"> | |
<head> | |
<title>PDF出力テスト</title> | |
<style> | |
.page { | |
page-break-after: always; | |
page-break-inside: avoid; | |
} | |
.page:last-child{ | |
page-break-after: auto; | |
} | |
</style> | |
</head> | |
<body> | |
@foreach ($pages as $page) | |
<div class="page"> | |
{{ $page }}ページ目 | |
</div> | |
@endforeach | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Route::get('/', function() { | |
$pdf = PDF::loadView('pdf', ['pages' => range(1, 3)]) | |
->setPaper('A4') // 用紙サイズ | |
->setOption('encoding', 'utf-8') // Encoding | |
->setOption('margin-top', 10) // 上マージン | |
->setOption('margin-bottom', 10) // 下マージン | |
->setOption('margin-left', 10) // 左マージン | |
->setOption('margin-right', 10) // 右マージン | |
->setOption('orientation', 'Landscape') // 横向き | |
->setOption('header-font-size', 16) // ヘッダーフォントサイズ | |
->setOption('header-center', 'Header Center') // ヘッダー中央 | |
->setOption('header-left', 'Header Left') // ヘッダー右 | |
->setOption('header-right', 'Header Right') // ヘッダー左 | |
->setOption('footer-font-size', 16) // フッターフォントサイズ | |
->setOption('footer-left', 'Footter Left') // フッター右 | |
->setOption('footer-right', 'Footter Right') // フッター左 | |
->setOption('footer-center', '[page] ページ') // フッター中央 [page]でページ番号が自動で入ります | |
->setOption('header-font-name', 'IPAexMincho') // ヘッダーフォント名 | |
->setOption('footer-font-name', 'IPAexMincho'); // フッターフォント名 | |
// インラインでPDF表示 | |
return $pdf->inline(); | |
// ダウンロードする場合 | |
return $pdf->download('download.pdf'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment