使用 wkhtmltopdf snappy php 中的发票 pdf Laravel
Invoice pdf in php with wkhtmltopdf snappy Laravel
大家好,我必须在我的 LARAVEL 项目中制作发票 pdf。
我成功地使用此代码生成了一个 pdf 文件:
$path_name_file = '../ArchivePdf/'. $name_file . '.pdf';
if ($document->type->type == 'A'){
$pdf = SnappyPdf::loadView('ribbon.report.pdf-achat', ['document' =>$document])
->save($path_name_file);
}else{
$pdf = SnappyPdf::loadView('ribbon.report.pdf-new', ['document' =>$document])->save($path_name_file);
}
我的问题出在 blade 视图(HTML 模板)中,我想放置页眉和页脚以及带有项目
的主 table
我希望页脚出现在所有页面上
我该怎么做?
谢谢
这是我的实际 html 观点:
<!DOCTYPE html>
<html>
<header>
<meta charset="utf-8">
<title>PDF Devis</title>
{{--<link href="{{ asset("/css/style_pdf.css")}}" rel="stylesheet" type="text/css" />--}}
<style>
.header-1{
border-top-left-radius: 7px;
border-top-right-radius: 7px;
/*left: 5%;*/
width: 100%;
border-style: solid;
font-size: 13px;
border-width: 2px;
}
th {
background-color: rgba(158, 158, 158, 0.22);
text-align: center;
}
.line{
width: 100%;
}
.line tr{
padding: 0;
}
.td-20{
width:20%
}
.td-30{
width:30%
}
.td-70{
width: 70%;
}
.td-40{
width: 40%;
}
.td-50{
width: 50%;
}
.img img{
width:100%; height:auto;
}
.name-soc{
font-size: 25px;
color: orangered;
direction: rtl;
font-family: arial;
font-style: bold;
}
.space{
padding-top: 20px;
}
.title{
font-weight: bold;
height: 50px;
color: white;
background-color: rgba(255, 87, 34, 0.89);
font-size: 25px;
border-radius: 5px;
bottom: 15px;
text-align: center;
}
.items{
}
.more_line{
height: 17px;
}
/*.items-table{*/
/*page-break-after: always;*/
/*page-break-inside: avoid;*/
/*}*/
thead { display: table-header-group }
tfoot { display: table-row-group }
.items-row { page-break-inside: avoid }
table { border-collapse: separate }
.note-table{
text-align: right;
width: 100%;
}
</style>
</header>
<body>
<table class="line">
<tr>
<td rowspan="4" class="td-30">
<div class="img"> <img src="{{ public_path('/ribbon/pdf/fre.jpg') }}" alt="logo"/></div>
</td>
<td class="td-30">
<div></div>
</td>
<td class="td-40">
<div class="name-soc">
דקופלוס פרקט בע״מ
</div>
</td>
</tr>
<tr>
<td class="td-30">
<div></div>
</td>
<td class="td-40">
<div class="name-soc">
</div>
</td>
</tr>
<tr>
<td class="td-20">
<div></div>
</td>
<td class="td-20">
<div></div>
</td>
</tr>
<tr>
<td class="td-20">
<div></div>
</td>
<td class="td-20">
<div></div>
</td>
</tr>
</table>
<table class="line">
<tr class="entete">
<td class="logo">
</td>
<td class="donnee_soc">
<div dir="rtl">{{trans('dcp_pdf.num_doc')}} : {{ $document->code }} </div>
</td>
</tr>
<tr>
<td class="td-50">
<div>
<table class="header-1" dir="rtl">
<tr>
<th colspan="2">{{trans('dcp_pdf.coord_cust')}}</th>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.name')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['name'] }} {{ $document['customer']['surname'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.adress')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['adress']['street'] }} {{ $document->adress->city->cityT[0]->texte }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.telephone')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['phone'] }} / {{ $document['customer']['phone2'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.mail')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['email'] }}</div>
</td>
</tr>
</table>
</div>
</td>
<td class="td-50">
<div>
<table class="header-1" dir="rtl">
<tr>
<th colspan="2">{{trans('dcp_pdf.coord_fact')}}</th>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.name')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['name'] }} {{ $document['customer']['surname'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.adress')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['adress']['street'] }} {{ $document->adress->city->cityT[0]->texte }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.telephone')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['phone'] }} / {{ $document['customer']['phone2'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.mail')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['email'] }}</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr >
<td colspan="2" class="space">
<div>
<table class="header-1" dir="rtl">
<tr>
<th colspan="2">{{trans('dcp_pdf.coord_livraison')}}</th>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.name')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['name'] }} {{ $document['customer']['surname'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.adress')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['adress']['street'] }} {{ $document->adress->city->cityT[0]->texte }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.telephone')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['phone'] }} / {{ $document['customer']['phone2'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.mail')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['email'] }}</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr >
<td colspan="2" class="space">
<div class="title" dir="rtl">
{{ $document->type->typeT[0]->texte }} - {{ $document->code }}
</div>
</td>
</tr>
<tr >
<td colspan="2" class="space">
<table class="items header-1 items-table" dir="rtl">
<thead>
<tr class="more_line">
<th class="Désignation" >{{trans('dcp_pdf.desc_article')}}</th>
<th class="other">{{trans('dcp_pdf.conditionnement')}}</th>
<th class="other">{{trans('dcp_pdf.quantity_m2')}}</th>
<th class="other">{{trans('dcp_pdf.nb_colis')}}</th>
<th class="other">{{trans('dcp_pdf.pu_ht')}}</th>
<th class="other">{{trans('dcp_pdf.discount')}}</th>
<th class="other">{{trans('dcp_pdf.total_ht')}}</th>
</tr>
</thead>
@foreach($document->items as $item)
<tr class="1 items-row">
<td class="Designation" dir="rtl"><div dir="rtl">{{ $item->material->textes[0]->texte }}</div></td>
<td class="Cdt"></td>
<td class="Qtem2">{{ $item->quantity }}</td>
<td class="Nb_colis">{{ $item->qte_col }}</td>
<td class="PU">{{ number_format($item->price, 2, '.', ',') }}</td>
<td class="Rem">{{ number_format($item->discount, 2, '.', ',') }} {{ $item->typeRemise->code }}</td>
<td class="Total"> {{ number_format($item->price_wo_vat, 2, '.', ',') }}</td>
</tr>
@endforeach
@for ($i = $document->items->count(); $i < 20; $i++)
<tr class="more_line">
<td class="Designation" dir="rtl"><div dir="rtl"></div></td>
<td class="Cdt"></td>
<td class="Qtem2"></td>
<td class="Nb_colis"></td>
<td class="PU"></td>
<td class="Rem"></td>
<td class="Total"></td>
</tr>
@endfor
</table>
</td>
</tr>
<tr >
<td colspan="2" >
<table class="note-table" dir="rtl">
<tr class="" >
<td>
<div class="encadre_data">{{ $document['note'] }} </div>
</td>
</tr>
<tr class="" >
<td >
<div class="encadre_data">{{ $document['comment'] }} </div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="td-30">
<div>
<table class="header-1" dir="rtl">
<tr>
<td>{{trans('dcp_pdf.montant_ht')}}</td>
<td>{{ number_format($document->amount_wo_taxe, 2, '.', ',') }}</td>
</tr>
<tr>
<td>{{trans('dcp_pdf.dont_remise')}}</td>
<td></td>
</tr>
@if ($document['customer']['code_tva'] === 1)
<tr>
<td>{{trans('dcp_pdf.tva')}} {{ number_format($document->taxe, 2, '.', ',') }} %</td>
<td>{{ number_format($document->amount - $document->amount_wo_taxe, 2, '.', ',') }}</td>
</tr>
@endif
<tr>
<td>{{trans('dcp_pdf.montant_ttc')}}</td>
<td>{{ number_format($document->amount, 2, '.', ',') }}</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</div>
</td>
<td class="td-70">
<div>
<table class="header-1" dir="rtl">
<tr>
<th colspan="4">{{trans('dcp_pdf.reglements')}}</th>
</tr>
<tr>
<th>{{trans('dcp_pdf.date')}}</th>
<th>{{trans('dcp_pdf.description')}}</th>
<th>{{trans('dcp_pdf.montant')}}</th>
<th>{{trans('dcp_pdf.mode_paiement')}}</th>
</tr>
@foreach($document->reglements as $reglement)
<tr>
<td>{{ $reglement->date }}</td>
<td>{{ $reglement->description }}</td>
<td>{{ number_format($reglement->amount, 2, '.', ',') }}</td>
<td>{{ $reglement->mode->modePaiementT[0]->texte }}</td>
</tr>
@endforeach
</table>
</div>
</td>
</tr>
<tr>
<td>
<div></div>
</td>
<td>
<div></div>
</td>
</tr>
<tr>
<td>
<div></div>
</td>
<td>
<div></div>
</td>
</tr>
<tr>
<td>
<div></div>
</td>
<td>
<div></div>
</td>
</tr>
<tr>
<td>
<div></div>
</td>
<td>
<div></div>
</td>
</tr>
<tr>
<td>
<div></div>
</td>
<td>
<div></div>
</td>
</tr>
</table>
</body>
</html>
这是 documentation 关于页眉和页脚的 Wkhtmltopdf
支持。
你可以试试
对于页眉
setOption('header-html', 'Your Header');
用于页脚
setOption('footer-html', 'Your Footer');
只需确保您需要在 header/footer HTML!
的开头添加 <!DOCTYPE HTML><html lang='en-US'>
大家好,我必须在我的 LARAVEL 项目中制作发票 pdf。
我成功地使用此代码生成了一个 pdf 文件:
$path_name_file = '../ArchivePdf/'. $name_file . '.pdf';
if ($document->type->type == 'A'){
$pdf = SnappyPdf::loadView('ribbon.report.pdf-achat', ['document' =>$document])
->save($path_name_file);
}else{
$pdf = SnappyPdf::loadView('ribbon.report.pdf-new', ['document' =>$document])->save($path_name_file);
}
我的问题出在 blade 视图(HTML 模板)中,我想放置页眉和页脚以及带有项目
的主 table我希望页脚出现在所有页面上
我该怎么做?
谢谢
这是我的实际 html 观点:
<!DOCTYPE html>
<html>
<header>
<meta charset="utf-8">
<title>PDF Devis</title>
{{--<link href="{{ asset("/css/style_pdf.css")}}" rel="stylesheet" type="text/css" />--}}
<style>
.header-1{
border-top-left-radius: 7px;
border-top-right-radius: 7px;
/*left: 5%;*/
width: 100%;
border-style: solid;
font-size: 13px;
border-width: 2px;
}
th {
background-color: rgba(158, 158, 158, 0.22);
text-align: center;
}
.line{
width: 100%;
}
.line tr{
padding: 0;
}
.td-20{
width:20%
}
.td-30{
width:30%
}
.td-70{
width: 70%;
}
.td-40{
width: 40%;
}
.td-50{
width: 50%;
}
.img img{
width:100%; height:auto;
}
.name-soc{
font-size: 25px;
color: orangered;
direction: rtl;
font-family: arial;
font-style: bold;
}
.space{
padding-top: 20px;
}
.title{
font-weight: bold;
height: 50px;
color: white;
background-color: rgba(255, 87, 34, 0.89);
font-size: 25px;
border-radius: 5px;
bottom: 15px;
text-align: center;
}
.items{
}
.more_line{
height: 17px;
}
/*.items-table{*/
/*page-break-after: always;*/
/*page-break-inside: avoid;*/
/*}*/
thead { display: table-header-group }
tfoot { display: table-row-group }
.items-row { page-break-inside: avoid }
table { border-collapse: separate }
.note-table{
text-align: right;
width: 100%;
}
</style>
</header>
<body>
<table class="line">
<tr>
<td rowspan="4" class="td-30">
<div class="img"> <img src="{{ public_path('/ribbon/pdf/fre.jpg') }}" alt="logo"/></div>
</td>
<td class="td-30">
<div></div>
</td>
<td class="td-40">
<div class="name-soc">
דקופלוס פרקט בע״מ
</div>
</td>
</tr>
<tr>
<td class="td-30">
<div></div>
</td>
<td class="td-40">
<div class="name-soc">
</div>
</td>
</tr>
<tr>
<td class="td-20">
<div></div>
</td>
<td class="td-20">
<div></div>
</td>
</tr>
<tr>
<td class="td-20">
<div></div>
</td>
<td class="td-20">
<div></div>
</td>
</tr>
</table>
<table class="line">
<tr class="entete">
<td class="logo">
</td>
<td class="donnee_soc">
<div dir="rtl">{{trans('dcp_pdf.num_doc')}} : {{ $document->code }} </div>
</td>
</tr>
<tr>
<td class="td-50">
<div>
<table class="header-1" dir="rtl">
<tr>
<th colspan="2">{{trans('dcp_pdf.coord_cust')}}</th>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.name')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['name'] }} {{ $document['customer']['surname'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.adress')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['adress']['street'] }} {{ $document->adress->city->cityT[0]->texte }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.telephone')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['phone'] }} / {{ $document['customer']['phone2'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.mail')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['email'] }}</div>
</td>
</tr>
</table>
</div>
</td>
<td class="td-50">
<div>
<table class="header-1" dir="rtl">
<tr>
<th colspan="2">{{trans('dcp_pdf.coord_fact')}}</th>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.name')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['name'] }} {{ $document['customer']['surname'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.adress')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['adress']['street'] }} {{ $document->adress->city->cityT[0]->texte }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.telephone')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['phone'] }} / {{ $document['customer']['phone2'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.mail')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['email'] }}</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr >
<td colspan="2" class="space">
<div>
<table class="header-1" dir="rtl">
<tr>
<th colspan="2">{{trans('dcp_pdf.coord_livraison')}}</th>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.name')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['name'] }} {{ $document['customer']['surname'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.adress')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['adress']['street'] }} {{ $document->adress->city->cityT[0]->texte }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.telephone')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['phone'] }} / {{ $document['customer']['phone2'] }}</div>
</td>
</tr>
<tr class="" >
<td>
<div style="width: 20%">{{trans('dcp_pdf.mail')}}</div>
</td>
<td>
<div class="encadre_data">{{ $document['customer']['email'] }}</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr >
<td colspan="2" class="space">
<div class="title" dir="rtl">
{{ $document->type->typeT[0]->texte }} - {{ $document->code }}
</div>
</td>
</tr>
<tr >
<td colspan="2" class="space">
<table class="items header-1 items-table" dir="rtl">
<thead>
<tr class="more_line">
<th class="Désignation" >{{trans('dcp_pdf.desc_article')}}</th>
<th class="other">{{trans('dcp_pdf.conditionnement')}}</th>
<th class="other">{{trans('dcp_pdf.quantity_m2')}}</th>
<th class="other">{{trans('dcp_pdf.nb_colis')}}</th>
<th class="other">{{trans('dcp_pdf.pu_ht')}}</th>
<th class="other">{{trans('dcp_pdf.discount')}}</th>
<th class="other">{{trans('dcp_pdf.total_ht')}}</th>
</tr>
</thead>
@foreach($document->items as $item)
<tr class="1 items-row">
<td class="Designation" dir="rtl"><div dir="rtl">{{ $item->material->textes[0]->texte }}</div></td>
<td class="Cdt"></td>
<td class="Qtem2">{{ $item->quantity }}</td>
<td class="Nb_colis">{{ $item->qte_col }}</td>
<td class="PU">{{ number_format($item->price, 2, '.', ',') }}</td>
<td class="Rem">{{ number_format($item->discount, 2, '.', ',') }} {{ $item->typeRemise->code }}</td>
<td class="Total"> {{ number_format($item->price_wo_vat, 2, '.', ',') }}</td>
</tr>
@endforeach
@for ($i = $document->items->count(); $i < 20; $i++)
<tr class="more_line">
<td class="Designation" dir="rtl"><div dir="rtl"></div></td>
<td class="Cdt"></td>
<td class="Qtem2"></td>
<td class="Nb_colis"></td>
<td class="PU"></td>
<td class="Rem"></td>
<td class="Total"></td>
</tr>
@endfor
</table>
</td>
</tr>
<tr >
<td colspan="2" >
<table class="note-table" dir="rtl">
<tr class="" >
<td>
<div class="encadre_data">{{ $document['note'] }} </div>
</td>
</tr>
<tr class="" >
<td >
<div class="encadre_data">{{ $document['comment'] }} </div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="td-30">
<div>
<table class="header-1" dir="rtl">
<tr>
<td>{{trans('dcp_pdf.montant_ht')}}</td>
<td>{{ number_format($document->amount_wo_taxe, 2, '.', ',') }}</td>
</tr>
<tr>
<td>{{trans('dcp_pdf.dont_remise')}}</td>
<td></td>
</tr>
@if ($document['customer']['code_tva'] === 1)
<tr>
<td>{{trans('dcp_pdf.tva')}} {{ number_format($document->taxe, 2, '.', ',') }} %</td>
<td>{{ number_format($document->amount - $document->amount_wo_taxe, 2, '.', ',') }}</td>
</tr>
@endif
<tr>
<td>{{trans('dcp_pdf.montant_ttc')}}</td>
<td>{{ number_format($document->amount, 2, '.', ',') }}</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</div>
</td>
<td class="td-70">
<div>
<table class="header-1" dir="rtl">
<tr>
<th colspan="4">{{trans('dcp_pdf.reglements')}}</th>
</tr>
<tr>
<th>{{trans('dcp_pdf.date')}}</th>
<th>{{trans('dcp_pdf.description')}}</th>
<th>{{trans('dcp_pdf.montant')}}</th>
<th>{{trans('dcp_pdf.mode_paiement')}}</th>
</tr>
@foreach($document->reglements as $reglement)
<tr>
<td>{{ $reglement->date }}</td>
<td>{{ $reglement->description }}</td>
<td>{{ number_format($reglement->amount, 2, '.', ',') }}</td>
<td>{{ $reglement->mode->modePaiementT[0]->texte }}</td>
</tr>
@endforeach
</table>
</div>
</td>
</tr>
<tr>
<td>
<div></div>
</td>
<td>
<div></div>
</td>
</tr>
<tr>
<td>
<div></div>
</td>
<td>
<div></div>
</td>
</tr>
<tr>
<td>
<div></div>
</td>
<td>
<div></div>
</td>
</tr>
<tr>
<td>
<div></div>
</td>
<td>
<div></div>
</td>
</tr>
<tr>
<td>
<div></div>
</td>
<td>
<div></div>
</td>
</tr>
</table>
</body>
</html>
这是 documentation 关于页眉和页脚的 Wkhtmltopdf
支持。
你可以试试
对于页眉
setOption('header-html', 'Your Header');
用于页脚
setOption('footer-html', 'Your Footer');
只需确保您需要在 header/footer HTML!
的开头添加<!DOCTYPE HTML><html lang='en-US'>