Home » Php » How to table row break after print pdf page?

How to table row break after print pdf page?

Posted by: admin October 26, 2017 Leave a comment

Questions:

I am newly php developer,I have create html file print custom pdf function multi page working fine.But table row hide after print pdf header & footer section. please help me how to resolve that issue. I will create table row each function script not working. Or it is possible to insert the table header on each page, where the table was splitted.

html code

<!-- font awesome css -->
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- font awesome css -->
<?php
session_start();
//$fmt = new NumberFormatter('zh_Hans', NumberFormatter::CURRENCY);
if(isset($_POST['result'])) {
$data = $_POST['result'];
$proforma_invoice_amount=0;
$record = json_decode($data, true);
if($record['proforma_amount_c']){
$proforma_invoice_amount=$record['proforma_amount_c'];
}
//invoice date
$yrdata= strtotime($record['active_date']);
$inv_date = date('d-M-Y', $yrdata);
//invoice due date
$invDueDate = strtotime($record['invoice_due_date_c']);
if (empty($record['invoice_due_date_c'])) {
$due_date = '';
}else {
$due_date = date('d/m/Y', $invDueDate);
}
//country name
if ($record['client_location_c'] == 'germany') {
$country = 'Germany';
$address = '<span>'.$record['recipient_address'].'</span><br/><span>'.$record['recipient_address_postalcode'].'</span><br/><span>'.$record['recipient_address_city'].'</span>';
}else {
$country = 'Romania';
$address = '<span>'.$record['recipient_address'].'</span><br/><span>'.$record['recipient_address_city'].'</span><br/><span>'.$record['recipient_address_state'].' '.$record['recipient_address_country'].'</span><br/><span>Trade registry: '.$record['recipient_tax_no'].'</span><br/><span> Unique no.:'.$record['recipient_vat_id'].'</span>';
}
if ($record['recipient_phone_number_c'] == NULL) {
$phone = 'phonefa';
}else {
$phone = '';
}
if ($record['recipient_fax_number_c'] == NULL) {
$fax= 'faxfa';
}else {
$fax = '';
}
//proforma invoice
if ($record['proforma_invoice_c'] == 'yes') {
$invoice_title = "Proforma Invoice";
}else {
$invoice_title = "Invoice On Behalf And In The Name of Service Providers";
}
if ($record['region_c'] == 'Non_EU_client_and_freelancer_provider') {
$clientvatId = '';
//  $region = 'NON EU CLIENT and freelancer provider';
$regClass = 'region-title';
$reverse = 'Reverse Charge to be applied related to VAT.';
$content = 'This invoice includes the advanced cost of the respective guides as well as the commission of GGS GmbH. Regarding the service of the guides legal are established between you and the guides directly. Service non-taxiable in Germany.';
}else if($record['region_c'] == 'Non_EU_client_and_employed_provider'){
$clientvatId = '';
//  $region = 'NON EU CLIENT and employed provider';
$regClass = 'region-title';
$reverse = 'Reverse Charge to be applied related to VAT.';
$content = 'Invoiced services are being provided through an employed guide of GGS GmbH. Service non-taxable in Germany.';
}else if($record['region_c'] == 'German_client_and_freelancer_provider'){
$clientvatId = $record['client_vat_id'];
//  $region = 'GERMAN CLIENT and freelancer provider';
$regClass = 'region-title';
$reverse = '';
$content = 'This invoice includes the advanced cost of the respective guides as well as the commission of GGS GmbH. Regarding the service of the guides, legal relation are established between you and the guides directly. GGS pays taxes analog to the margin taxation conformable to Par.25 UstG.';
}else if($record['region_c'] == 'German_client_and_employed_provider'){
$clientvatId = $record['client_vat_id'];
//    $region = 'GERMAN CLIENT and employed provider';
$regClass = 'region-title';
$reverse = '';
$content = 'Invoiced services are being provided through an employed guide of GGS GmbH.';
}else if($record['region_c'] == 'EU_client_and_freelancer_provider'){
$clientvatId = $record['client_vat_id'];
//  $region = 'EU CLIENT and freelancer provider';
$regClass = 'region-title';
$reverse = 'Reverse Charge to be applied according to EU regulation.';
$content = 'This invoice includes the advanced cost of the respective guides as well as the commission of GGS GmbH. Regarding the service of the guides legal are established between you and the guides directly. Service non-taxiable in Germany.';
}else if ($record['region_c'] == 'EU_client_and_employed_provider') {
$clientvatId = $record['client_vat_id'];
//  $region = 'EU CLIENT and employed provider';
$regClass = 'region-title';
$reverse = 'Reverse Charge to be applied according to EU regulation.';
$content ='Invoiced services are being provided through an employed guide of GGS GmbH. Service non-taxable in Germany.';
}else {
$clientvatId = '';
//  $region = '';
$regClass = '';
$reverse = 'Reverse Charge to be applied related to VAT.';
$content = 'This invoice includes the advanced cost of the respective guides as well as the commission of GGS GmbH. Regarding the service of the guides legal are established between you and the guides directly. Service non-taxiable in Germany.';
}
//invoice
$invoice = $record[0]['clientinvoicedetails'];
$vendorDetails = $record[0]['vendorDetails'];
}
?>
<div class="app-box" id="printable">
<div class="container">
<div class="header-wrapper">
<div class="brand">
<img src="themes/default/images/company_logo.png?v=irxcvcunnaqWHVYHqEAgiw&amp;logo_md5=69fbb4688c6fcc37685a678b824f819b" alt="" style="width:150px;">
</div>
<div class="country-bg"></div>
<div class="country-name">
<h3><?=$country?></h3>
</div>
</div>
<!--Header content End Here-->
<div class="page-content">
<div class="address">
<div class="address-left">
<p><strong>[email protected]</strong></p>
<span><?=$record['client_name']?></span><br>
<span><?=$record['client_address']?></span><br>
<span><?=$record['client_address_city']?></span><br>
<span><?=$record['client_address_state']?>, <?=$record['client_address_country']?></span><br>
<span><?=$record['client_address_postalcode']?></span><br>
<span style="font-weight:bold;margin-top:25px;"><?=$clientvatId?></span>
</div>
<div class="address-right">
<p><?=$address ?></p>
<p>
<span><i class="fa fa-phone <?=$phone?>"></i> <?=$record['recipient_phone_number_c'] ?></span><br>
<span><i class="fa fa-print <?=$fax?>"></i> <?=$record['recipient_fax_number_c'] ?></span>
</p>
</div>
</div>
<!-- <div class="invoice_head-bg"></div> -->
<div class="invoice-head">
<div class="invoice_head-bg"></div>
<h3><?=$invoice_title?></h3>
<p>for the assignment of guided tours, assistances, tour escorts, transfers</p>
</div>
<div class="invoice-details">
<div class="invoice-number">
<p><strong>Invoice number :</strong> <span><?=$record['ginvo_client_invoice_no']?></span></p>
<p><strong>Invoice date :</strong> <span><?=$inv_date?></span></p>
</div>
<div class="invoice-info">
<span>(please invoice number and date with your payment)</span>
</div>
</div>
<div class="invoice-table">
<table class="table">
<thead>
<tr>
<th>Group ID</th>
<th>Date</th>
<th>City</th>
<th>Service</th>
<th>Duration</th>
<th>Note</th>
<th>Rate</th>
</tr>
</thead>
<tbody>
<?php
$count = 0;
$index=0;
foreach ($invoice as $inv) {
$count+= $inv['rate_with_vat'];
?>
<tr>
<td><?=$inv['group_id']?></td>
<td><?=$inv['service_date']?></td>
<td><?=$inv['city']?></td>
<td><?=$inv['service']?></td>
<td><?=$inv['duration']?></td>
<td><?=$inv['notes']?></td>
<td class="text-right"><span><?php echo "&#0128"; ?></span> <?=$inv['rate_with_vat']?></td>
</tr>
<?php
foreach ($vendorDetails as $vendorDetail) {
// print_r($vendorDetail);
if($vendorDetail['id']==$inv['vendor_id']){
?>
<tr style="text-align:center;">
<td colspan="7"><?=$vendorDetail['first_name']?>,<?=$vendorDetail['address_street']?>,<?=$vendorDetail['address_city']?>,<?=$vendorDetail['address_state']?>,<?=$vendorDetail['address_country']?>,<?=$vendorDetail['address_postalcode']?></td>
</tr>
<?php
}
}
$index++;
} ?>
<tr class="footer">
<td colspan="6" class="text-right" style="text-transform:uppercase;"><strong>Total Sum</strong></td>
<td class="text-right"><span><?php echo "&#0128"; ?></span> <strong><?=$count ?></strong></td>
</tr>
<?php
if($proforma_invoice_amount>0&&$record['proforma_invoice_c'] != 'yes'){
?>
<tr class="footer">
<td colspan="6" class="text-right" style="text-transform:uppercase;"><strong>Paid with Proforma</strong></td>
<td class="text-right"><span><?php echo "&#0128"; ?></span> <strong><?php echo number_format((float)$proforma_invoice_amount, '2', '.', '');?></strong></td>
</tr>
<tr class="footer">
<td colspan="6" class="text-right" style="text-transform:uppercase;"><strong>Rest to Pay</strong></td>
<td class="text-right"><span><?php echo "&#0128"; ?></span> <strong><?=$count-$proforma_invoice_amount ?></strong></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<div class="vat text-right">
<span><?=$reverse?></span>
</div>
<div class="invoice-include">
<p><?=$content?></p>
</div>
<div class="due-date">
<p class="">Our invoice falls due immediately and is to be paid in full within</p>
<div class="date"><span><?=$due_date ?></span></div>
</div>
<?php if ($record['client_location_c'] == 'germany'){ ?>
<div class="thanks">
<p>Thank you for your order!</p>
</div>
<?php }else { ?>
<div class="romania-cnp">
<p class="">Intocmit de: Andreea loana</p>
<div class="cnp"><span>CNP: 2950318151935</span></div>
</div>
<?php } ?>
<div class="manufacture-address">
<?php if ($record['client_location_c'] == 'germany'){ ?>
<div class="display-flex">
<div class="text-left">
<p>
<span>Global Guide Services GmbH</span><br>
<span>Münchner Str. 23</span><br>
<span>D-83703 Gmund a. Tegernsee</span><br>
<span>Local Court Munich, HRB 223121</span>
</p>
</div>
<div class="text-center">
<p>
<span>Managing Director: Siavash Sartipi</span><br>
<span><i class="fa fa-phone"></i> +49 151 74327305</span><br>
<span><i class="fa fa-print"></i> +49 721 509663197</span><br>
<span>www.global-guide-services.com</span>
</p>
</div>
<div class="text-right">
<p>
<span>VAT Nr DE 305563525</span><br>
<span>Tax Nr 139/127/50609</span><br>
<span>IBAN DE41 7001 0080 0697 1208 00</span><br>
<span>BIC/SWIFT PBNKDEFF</span>
</p>
</div>
</div>
<?php }else { ?>
<div class="text-center address_Raif">
<p>
<span>Account holder: <label>Global Guides Services SRL,</label> Bank:Raiffeisen</span><br>
<span>IBAN RO 92 RZBR 0000 0600 1754 9626 BIC(SWIFT):RZBRROBU</span><br>
<span>VAT: RO34622172</span><br>
</p>
</div>
<?php } ?>
</div>
</div>
<!--Page content End Here-->
</div>
</div>
<style type="text/css">
/*@media print {
.header-wrapper{
height: 20% !important;
}
.manufacture-address{
height: 20% !important;
}
}*/
@page {
size: auto;   /* auto is the initial value */
margin: 0 auto;  /* this affects the margin in the printer settings */
}
body {
/*font-family: Aria 'Roboto', sans-serif;*/
font-family: Arial, Verdana, Helvetica, sans-serif;
font-size: 12px;
margin: 15mm 0mm 35mm 0mm;
background: #efefef;
-webkit-print-color-adjust: exact;
page-break-after:always;
position: relative;
}
.app-box{
margin-top: 30px;
}
.container {
width: 980px;
margin: 0 auto;
/*height: 980px;*/
position: relative;
}
.header-wrapper {
/*margin-top: 15px;*/
height: 65px;
border-bottom: 3px solid #344d90;
clear: both;
position: fixed;
top: 0;
width: 980px;
background: #fff;
}
.header-wrapper .brand {
float: left;
width: 33%;
margin-top: 7px;
}
.header-wrapper .country-name {
float: right;
padding: 10px 40px;
}
.header-wrapper .country-name h3 {
color: #344d90;
z-index: 10000;
font-weight: 600;
font-size: 18px;
}
.region-title{
width: auto;
padding: 1px 22px;
float: left;
border: 2px solid #f532d4;
color: #f532d4;
line-height: 0;
margin-top: 10px;
}
.page-content {
font-size: 14px;
/*padding: 10px;*/
margin-top: 75px;
}
.address{
display: flex;
justify-content: space-between;
line-height: 20px;
}
.address .address-left {
font-size: 16px;
}
.address .address-right {
text-align: right;
z-index: 10;
}
.invoice-head{
text-align: center;
position: relative;
}
.invoice-head .invoice_head-bg {
height: 61px;
position: absolute;
z-index: -1;
width: 100%;
background: #d4d2d2;
/*background: -webkit-linear-gradient(#d4d2d2, rgba(230, 224, 224, 0));
background: -o-linear-gradient(#d4d2d2, rgba(230, 224, 224, 0));
background: -moz-linear-gradient(#d4d2d2, rgba(230, 224, 224, 0));
background: linear-gradient(#d4d2d2, rgba(230, 224, 224, 0));*/
-webkit-print-color-adjust: exact;
}
.invoice-head h3 {
text-transform: uppercase;
margin-bottom: 0;
font-size: 16px;
word-spacing: -2px;
padding: 5px;
}
.invoice-head p{
margin-top: 5px;
font-size: 16px;
word-spacing: 4px;
}
.invoice-details{
display: flex;
}
.invoice-details .invoice-info {
margin: 25px 40px;
}
/*.invoice-table {
max-height: 500px;
overflow-y: scroll;
overflow-x: hidden;
height: 300px;
}*/
.table {
width: 100%;
max-width: 100%;
margin-bottom: 1rem;
border-collapse: collapse;
margin: 20px 0 4px 0;
}
/*table.table{
page-break-inside:avoid; page-break-after:always;
}*/
.table th, .table td {
padding: .70rem;
vertical-align: top;
border-top: 1px solid #eceeef;
width: 13%;
}
/*div.tablePage {
page-break-inside:avoid; page-break-after:always;
}*/
.table thead tr {
background: #7d93ce;
-webkit-print-color-adjust: exact;
}
.table tbody tr:nth-of-type(even) {
background-color: rgba(123, 159, 234, 0.26);
-webkit-print-color-adjust: exact;
}
.table tbody tr.footer {
background: #a9b8e2;
-webkit-print-color-adjust: exact;
margin-top: -20% !important;
margin-bottom: 50% !important
}
.table tbody tr td{
page-break-inside: avoid;
page-break-after: always;
}
*, ::after, ::before {
-webkit-box-sizing: inherit;
box-sizing: inherit;
}
.invoice-include {
width: 70%;
line-height: 21px;
}
.due-date{
display: flex;
margin-top: -15px;
}
.due-date .date {
margin: 15px 40px;
}
.romania-cnp{
display: flex;
margin-top: 30px;
margin-bottom: 30px;
}
.romania-cnp .cnp {
margin: 12px 40px;
}
.thanks {
margin-bottom: 100px;
}
.manufacture-address {
position: fixed;
bottom: 0;
width: 980px;
height: 100px;
margin-top: 100px;
}
.display-flex {
display: flex;
justify-content: space-between;
line-height: 18px;
font-size: 14px;
position: relative;
width: 100%;
bottom: 0;
clear: both;
page-break-after:always;
background: #fff;
}
.manufacture-address .address_Raif{
width: 100%;
}
.manufacture-address .address_Raif label{
text-transform: uppercase;
}
.phonefa, .faxfa{
display: none;
}
/*==== Common Styles =====*/
.text-center {
text-align: center;
}
.text-right {
text-align: right;
font-style: initial;
}
.country-bg{
height: 210px;
width: 200px;
/*right: 181px;*/
position: absolute;
right: 0px;
background: #bdc9ec;
background: -webkit-linear-gradient(#bdc9ec, rgba(107, 113, 181, 0));
background: -o-linear-gradient(#bdc9ec, rgba(107, 113, 181, 0));
background: -moz-linear-gradient(#bdc9ec, rgba(107, 113, 181, 0));
background: linear-gradient(#bdc9ec, rgba(107, 113, 181, 0));
-webkit-print-color-adjust: exact;
z-index: -1;
}
</style>

Script code

<script type="text/javascript">
print_order();
function print_order(){
window.print('#printable');
document.title= "<?=$record['ginvo_client_invoice_no']?>";
}
$(document).ready(function(){
var MaxHeight = 880;
var RunningHeight = 0;
var PageNo = 1;
$('table.table').each(function () {
// console.log($(this).height());
if (RunningHeight + $(this).height() > MaxHeight) {
RunningHeight = 0;
PageNo += 1;
}
RunningHeight += $(this).height();
$(this).attr("data-page-no", PageNo);
//  console.log($(this).attr("data-page-no", PageNo));
});
for(i = 1; i <= PageNo; i++){
//  console.log(i);
// //   //$('table.table').parent().append("<div class='tablePage'><hr /><table id='Table" + i + "'><tbody></tbody></table><hr /></div>");
// //
var rows = $('table tr[data-page-no="' + i + '"]');
console.log(rows);
// //
$('table' + i).find("tbody").append(rows);
}
//$('.table').remove();
});
</script>
Answers: