normalize.min.csspublic/vendor/normalizepaper.css hoặc paper.min.csspublic/vendor/paper-csspublic/vendor/paper-css/custom-paper.css/* --- Hacking multi pages sheet --- */
.sheet {
overflow: visible;
height: auto !important;
}
.paper-toolbar {
margin: auto;
background: #0d8a05;
padding: 5px;
z-index: 999;
}
.paper-toolbar-top {
position: fixed;
top: 0;
left: 0;
}
.paper-toolbar-bottom {
position: fixed;
bottom: 0;
left: 0;
}
.paper-toolbar.paper-toolbar-A3 {
width: 297mm;
}
.paper-toolbar.paper-toolbar-A3.landscape {
width: 420mm;
}
.paper-toolbar.paper-toolbar-A4 {
width: 210mm;
}
.paper-toolbar.paper-toolbar-A4.landscape {
width: 297mm;
}
.paper-toolbar.paper-toolbar-A5 {
width: 148mm;
}
.paper-toolbar.paper-toolbar-A5.landscape {
width: 210mm;
}
.paper-toolbar.letter.sheet {
width: 216mm;
}
.paper-toolbar.letter.landscape.sheet {
width: 280mm;
}
.paper-toolbar.legal.sheet {
width: 216mm;
}
.paper-toolbar.legal.landscape.sheet {
width: 357mm;
}
@media print {
.paper-show-when-print {
display: block !important;
}
.paper-hide-when-print {
display: none !important;
}
.no-print, .no-print *
{
display: none !important;
}
h2 {
page-break-before: always;
}
h3, h4 {
page-break-after: avoid;
}
pre, blockquote {
page-break-inside: avoid;
}
.page-break-inside-avoid {
page-break-inside: avoid;
}
tbody {
page-break-inside: avoid;
}
thead {
display: table-header-group;
margin-top: 100px;
}
table.report-container {
page-break-after:always;
}
thead.report-header {
display:table-header-group;
}
tfoot.report-footer {
display:table-footer-group;
}
}
views ---print ------layouts ---------paper.blade.php ------partials ---------paper-toolbar.blade.phpNội dung file
paper.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>@yield('title')</title>
<!-- Normalize or reset CSS with your favorite library -->
<link rel="stylesheet" href="{{ asset('vendor/normalize/normalize.min.css') }}">
<!-- Load paper.css for happy printing -->
<link rel="stylesheet" href="{{ asset('vendor/paper-css/paper.min.css') }}">
<link rel="stylesheet" href="{{ asset('vendor/paper-css/custom-paper.css') }}">
<!-- Set page size here: A5, A4 or A3 -->
<!-- Set also "landscape" if you need -->
<style>@page { size: @yield('paper-size') }</style>
@yield('custom-css')
</head>
<!-- Set "A5", "A4" or "A3" for class name -->
<!-- Set also "landscape" if you need -->
<body class="@yield('paper-class')">
@include('print.partials.paper-toolbar')
@yield('content')
</body>
</html>
Nội dung file paper-toolbar.blade.php
<section class="paper-toolbar paper-toolbar-top no-print">
<form>
<input type="button" value="In trang này" onClick="window.print()" />
</form>
@yield('paper-toolbar-top')
</section>
<section class="paper-toolbar paper-toolbar-bottom no-print">
<form>
<input type="button" value="In trang này" onClick="window.print()" />
</form>
@yield('paper-toolbar-bottom')
</section>
routes/web.phpRoute::get('/admin/sanpham/print', 'Backend\SanPhamController@print')->name('admin.sanpham.print');
In ấn trên giao diện index:resources/views/backend/sanpham/index.blade.php<!-- Tạo nút xem biểu mẫu khi in trên web
- Theo quy ước, các route đã được đăng ký trong file `web.php` đều phải được đặt tên để dễ dàng bảo trì code sau này.
- Đường dẫn URL là đường dẫn được tạo ra bằng route có tên `admin.sanpham.print`
- Sẽ có dạng http://tenmiencuaban.com/admin/sanpham/print
-->
<a href="{{ route('admin.sanpham.print') }}" class="btn btn-primary">In ấn</a>
print():print() dùng để lấy danh sách sản phẩm có trong table sanpham và hiển thị ra màn hình với các định dạng CSS in ấn.app/Http/Controllers/Backend/SanphamController.php/**
* Action hiển thị biểu mẫu xem trước khi in trên Web
*/
public function print()
{
$ds_sanpham = Sanpham::all();
$ds_loai = Loai::all();
return view('backend.sanpham.print')
->with('danhsachsanpham', $ds_sanpham)
->with('danhsachloai', $ds_loai);
}
print.blade.phpresources/views/sanphamresources/views/sanpham/print.blade.php@extends('print.layouts.paper')
@section('title')
Biểu mẫu Phiếu in danh sách sản phẩm
@endsection
@section('paper-size') A4 @endsection
@section('paper-class') A4 @endsection
@section('custom-css')
@endsection
@section('content')
<section class="sheet padding-10mm">
<article>
<table border="0" align="center">
<tr>
<td class="companyInfo" align="center">
Công ty TNHH Sunshine<br />
http://sunshine.com/<br />
(0292)3.888.999 # 01.222.888.999<br />
<img src="{{ asset('assets/storage/sunshine_wm64.png') }}" />
</td>
</tr>
</table>
<br />
<br />
<?php
$tongSoTrang = ceil(count($danhsachsanpham)/5);
?>
<table border="1" align="center" cellpadding="5">
<caption>Danh sách sản phẩm</caption>
<tr>
<th colspan="6" align="center">Trang 1 / {{ $tongSoTrang }}</th>
</tr>
<tr>
<th>STT</th>
<th>Hình sản phẩm</th>
<th>Tên sản phẩm</th>
<th>Giá gốc</th>
<th>Giá bán</th>
<th>Loại sản phẩm</th>
</tr>
@foreach ($danhsachsanpham as $sp)
<tr>
<td align="center">{{ $loop->index + 1 }}</td>
<td align="center">
<img class="hinhSanPham" src="{{ asset('assets/storage/photos/' . $sp->sp_hinh) }}" />
</td>
<td align="left">{{ $sp->sp_ten }}</td>
<td align="right">{{ $sp->sp_giaGoc }}</td>
<td align="right">{{ $sp->sp_giaBan }}</td>
@foreach ($danhsachloai as $l)
@if ($sp->l_ma == $l->l_ma)
<td align="left">{{ $l->l_ten }}</td>
@endif
@endforeach
</tr>
@if (($loop->index + 1) % 5 == 0)
</table>
<div class="page-break"></div>
<table border="1" align="center" cellpadding="5">
<tr>
<th colspan="6" align="center">Trang {{ 1 + floor(($loop->index + 1) / 5) }} / {{ $tongSoTrang }}</th>
</tr>
<tr>
<th>STT</th>
<th>Hình sản phẩm</th>
<th>Tên sản phẩm</th>
<th>Giá gốc</th>
<th>Giá bán</th>
<th>Loại sản phẩm</th>
</tr>
@endif
@endforeach
</table>
</article>
</section>
@endsection
Cùng nhau học tập, khám phá các kiến thức nền tảng về Lập trình web, mobile, database nhé.
Nền tảng kiến thức - Hành trang tới tương lai hân hạnh phục vụ Quý khách!
Khám phá, trải nghiệm ngay
Vui lòng đăng nhập để gởi bình luận!
Đăng nhậpChưa có bình luận nào!