DOMPDF Wrapper for Laravel (ok)
https://github.com/barryvdh/laravel-dompdf

Vi du 1:
routes\web.php
Route::get('/test', [TestController::class, 'test'])->name('test');
app\Http\Controllers\TestController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Barryvdh\DomPDF\Facade\Pdf;
class TestController extends Controller
{
public function test() {
$data = ['title' => 'Welcome to Viet Nam'];
$pdf = Pdf::loadView('pdf.invoice', $data);
//Nếu muốn hiển thị file pdf theo chiều ngang
// $pdf->setPaper('A4', 'landscape');
//Nếu muốn download file pdf
// return $pdf->download('myPDF.pdf');
//Nếu muốn preview in pdf
return $pdf->stream('myPDF.pdf');
}
}
resources\views\pdf\invoice.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<style>
.page-break {
page-break-after: always;
}
</style>
<body>
<h1>Welcome to ItSolutionStuff.com - {{ $title }}</h1>
<div class="page-break">ag</div>
</body>
</html>
PreviousTạo API và Authenticate nhanh chóng với package Laravel Sanctum (ok)NextSử dụng biến chung cho tất cả các view, Use variables common to all views (ok)
Last updated
Was this helpful?