CSS media prints 3 blank pages - css

I use Bootstrap 3, just to know. I cannot get rid of 3 blank pages after the first one. Don t know what is causing this problem.
HTML:
<table class="table table-bordered table-hover text-center" id="post_accesorii">
<thead>
<tr>
<th>Cod</th>
<th>Denumire</th>
<th>Cantitate</th>
<th>U.M.</th>
</tr>
</thead>
<tbody>
<form method="post" action="" autocomplete="off">
<?php
while($rowD = mysqli_fetch_assoc($query)) {
foreach ($rowD as $col => $val) {
if($val != "" && $val != "0" && $col != "nr_fisa" && $col != "id") {
$findum = mysqli_query($mysqli, "SELECT * FROM `stocuri` WHERE `cod` = '$col' AND `post1` = 'Accesorii'") or die(mysqli_error($mysqli));
$rowum = mysqli_fetch_array($findum);
echo "<tr class='piesa_folosita'>";
if($col == $rowum['cod'])
{
echo "<td>" . $col . "</td>";
echo "<td>" . $rowum['denumire'] . "</td>";
echo "<td>" . $val . "</td>";
echo "<td>" . $rowum['um'] . "</td>";
}
echo "</tr>";
} else {
}
}
}
?>
</tbody>
<tfoot>
<tr>
<th>Cod</th>
<th>Denumire</th>
<th>Cantitate</th>
<th>U.M.</th>
<tr>
</tfoot>
</table>
PRINT
print.css:
#media print {
html, body {
visibility: hidden;
height: 99% !important;
}
#post_accesorii, #post_accesorii * {
visibility: visible;
height: 99% !important;
}
#post_accesorii+#post_accesorii {
page-break-before: always;
}
}
In print preview, I have 3 blank pages after the first page with my table. I tried several solutions to remove them but none worked.
What can be the problem?

Your height: 99% !important; might be the problem, because the <body/> does not have parent

Your last print rule implies that there is more than one element that has the ID #post_accesorii . This should not be the case and is invalid HTML: IDs must only appear once in a page. So maybe that's the reason for your problems (I don't know what is around the code you posted, so that's all I can say).
To avoid that, make it a class instead of an ID: .post_accesorii and assign that to the HTML table tag/s via <table class="post_accesorii">

Related

How to display an ACF checkbox value in MPDF?

I have been working with mpdf and acf to generate a pdf. I can generate the pdf and display text values but I can't get it to display the values of a checkbox, it displays nothing.
This is the code that I have, what am I doing wrong? How do I get it to display something for the checkbox?
$offer is the checkbox that I am trying to display.
add_action('init', 'congres_redirect');
function congres_redirect() {
if(isset($_GET['offer'])) {
global $post; //ADD THIS
$offerid = $_GET['offer'];
$restname = get_field('restaurant_name', $offerid);
$offer = get_field_object('restaurant_offer', $offerid);
if( in_array( '2courses10', $offer ) or '2courses10' == $offer ) { $offer2for10='2 courses for 10'; }
$randNum = strtoupper(generateRandomString(5));
$date = date("Ymd");
$namecode = strtoupper(str_replace(' ', '', $restname));
$namestr = substr($namecode, 0, 6);
view_conferinta($restname, $randNum, $date, $namecode, $namestr);
}
}
function view_conferinta($restname, $randNum, $date, $namecode, $namestr) {
global $post;
$output = '<html>
<head><title>'.$restname.' | Eat Leeds</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head>
<body style="font-family:chelvetica;">
<table class="voucher-content" width="100%">
<tr>
<td width="60%"></td>
<td width="40%">
<table>
<tr class="inner-voucher">
<td class="offer-details" style="color: #fff !important;">'.$restname.'</td>
</tr>
<tr class="inner-voucher">
<td class="offer-details" style="color: #fff !important;">'.$offer2for10.'</td>
</tr>
<tr>
<td style="vertical-align: top; padding-top: 20px; padding-left: 280px; color: #fff;"><div class="vouchercode">Voucher Code: EL-'.$namestr.''.$date.'-'.$randNum.'</div></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>';
require_once __DIR__ . '/mpdf/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf(['debug' => true]);
$mpdf->WriteHTML($output);
$mpdf->Output('eatleeds-EL-'.$namestr.''.$date.'-'.$randNum.'.pdf','I');
exit;
}
You did not set a default value for $offer2for10.
You could also use a switch and loop into $offer value:
switch ($offer) {
case '2courses10':
$offer2for10 = "2 courses for 10";
break;
default:
$offer2for10 = "Unknown offer";
break;
}

How to create dynamic layouts with STATIC HTML using utility first approach (eg. bootstrap) [duplicate]

I am learning to use a utility first css approach to create a grid pattern layout for a variable number of search results. The appearance I want to achieve is described by this image here:
This was my solution using bootstrap css framework.
function loadMore() {
fetch('search-results.php?current='+document.querySelectorAll('.item').length)
.then(response=>response.text())
.then(result=>document.querySelector('.results').innerHTML += result);
}
body,div {padding:0;margin:0;}
.item {
display:block;
background:#333;
color:white;
border:2px solid white;
}
.item.col-12 {
height:75vh;
}
.item.col-6 {
height:50vh;
}
.item.col-4 {
height:30vh;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="results"></div>
<button type="button" onClick="loadMore()">Load More</button>
// PHP FILE - search-results.php
<?php
//$n = rand(1,10);
$n = $_REQUEST['current'] < 1 ? 1 : 8;
for($c=0;$c<$n;$c++)
{
$current = $c+intval($_REQUEST['current']);
if(
$current === 0 ||
($current-1)%8 === 0 ||
($current-3)%8 === 0 ||
($current+2)%8 === 0
)
echo '<div class="row">';
if($current === 0)
echo '<div class="item col-12">'.$current.'</div>';
else if(($current-1)%8 === 0 || ($current-2)%8 === 0)
echo '<div class="item col-6">'.$current.'</div>';
else
echo '<div class="item col-4">'.$current.'</div>';
if(
$current === 0 ||
($current-2)%8 === 0 ||
($current-2)%8 === 0 ||
($current-5)%8 === 0
)
echo '</div>';
}
My bootstrap approach has several problems that I do not know how to resolve:
When search-results.php returns a random number of items, the opening and closing <div class="row"> tags are not inserted at the right times after multiple "Load More" button clicks.
I don't like the arithmatic that I have to perform to properly place the open and closee <div class="row"> tags and to decide whether to write a col-12 || col-6 || col-4. This all seems unnecessarily complex.
QUESTION : What is the idiomatic way to use bootstrap (or any other utility-first css approach) to write a pattern grid layout that receives random number of results?
EXTRA - PLAIN APPROACH
My problem above can be solved using a plain CSS approach as shown with this code here:
// CSS FILE
body,div {padding:0;margin:0;}
.results {
display:flex;
flex-wrap:wrap;
}
.item {
display:block;
background:#333;
color:white;
box-sizing:border-box;
padding:10px;
width:33.333%;
height:30vh;
border:2px solid white;
}
.item:nth-child(1) {
width:100%;
height:75vh;
}
.item:nth-child(8n+2),
.item:nth-child(8n+3) {
width: 50%;
height:50vh;
}
// PHP FILE
<?php
$n = rand(1,10);
for($c=0;$c<$n;$c++)
echo '<div class="item">'.($c+intval($_REQUEST['current'])).'</div>';
The PHP code is much simpler and I do not have to deal with wrapping <div> elements.

How to implement CSS to powershell conver to html Output?

I have found interesting code that highlights a rows in table if the output is not desired
Source - https://www.youtube.com/watch?v=QdK3qM5jnYw&feature=youtu.be
$headLinkcheck += #'
<style>
body
{
background-color:white;
font-family:Arial;
font-size:8pt;
}
td,th
{
border:1px solid black;
border-collapse:collapse;
}
th
{
color:white;
background-color:black;
}
table, tr, td, th {padding:5px; margin: 0px;}
table {margin-left:50px;width: 80%;height:35%}
.danger {background-color:yellow;font-weight:bold}
.warn {background-color:blue}
</style>
'#
Ok now i have code that checks webistes and their status
function GetSiteStatus(){
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
[hashtable]$WebSiteInfo
)
process{
$Response = New-Object System.Collections.ArrayList
$WebSiteInfo.GetEnumerator() | %{
$Item = $_
try{
$status = Invoke-WebRequest -Uri $_.Value | %{
if(#('404','503','403') -match $_.StatusCode){
"$($Item.Key) The Site may be down, please check. - status is $($_.StatusCode)"
}else{
"OK"
}
}
$Response.Add([PSCustomObject]#{"Name"= $Item.Key; "Value"=$Item.Value; "Status"=$Status; "Link"=$($Item.value)}) | out-null
}catch{
$Status = "$($Item.Key), $_."
$Response.Add([PSCustomObject]#{"Name"= $Item.Key; "Value"=$Item.Value; "Status"=$Status; "Link"=$($Item.value)}) | out-null
}
}
return $Response
}
}
$html_url1 = #{
"Calendar" = "http:/";
} | GetSiteStatus | ConvertTo-Html -Head $headLinkcheck -Property Name,Value,Status,#{Label="Link";Expression={"<a href='$($_.Value)'>$($_.Name)</a>"}}
Add-Type -AssemblyName System.Web
[System.Web.HttpUtility]::HtmlDecode($html_url) | Out-File "\\servertest\xpbuild$\IT\Level0\scresult\servicecheck$global:servicecheckdate.htm" -Append # have to use it to creates clickable links
Now the last piece is second part of code which i found ,that checks each line in rows -theorically
[array]$html_url += $html_url1 i quess this might help code below to read values
[xml]$html = $html_url | ConvertTo-Html -Fragment
for ($i = 1; $i -le $html.table.tr.Count-1;$i++){
$class = $html.CreateAttribute("class")
if(($html.table.tr[$i].td[-1]) -ne "OK"){
$class.Value = "danger"
$html.table.tr[$i].attributes.append($class) | Out-Null
}
}
$body += #"
$($html.innerxml)
"#
Now the problem with this is i am not sure how to implement this last part to my code
I got variable- $html_url1 that contains all needed values from my function that checks webistes.
I am not sure how to add this piece - should I add it to my $html_url1 pipe? I tried and it fails. Can you suggest hopw to implement this ?
You can always just make the page from scratch and build whatever you want from there an example
$Sites = #{
"Google"="http://google.com";
"ErrorTest"="I Am Fake";
"Yahoo" = "http://Yahoo.com";
}
$OutFile = "C:\Test\Test.htm"
function GetSiteStatus(){
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
[hashtable]$WebSiteInfo
)
process{
$WebSiteInfo.GetEnumerator() | %{
$Item = $_
$Type
try{
$status = Invoke-WebRequest -Uri $_.Value | %{
if(#('404','503','403') -match $_.StatusCode){
"$($Item.Key) The Site may be down, please check. - status is $($_.StatusCode)"
$Type = "Warning"
}else{
"OK"
$Type = "Good"
}
}
return [PSCustomObject]#{"Name"= $Item.Key; "Value"=$Item.Value; "Status"=$Status; "Link"=$($Item.value); "Type"=$Type}
}catch{
$Type = "Error"
$Status = "$($Item.Key), $_."
return [PSCustomObject]#{"Name"= $Item.Key; "Value"=$Item.Value; "Status"=$Status; "Link"=$($Item.value); "Type"=$Type}
}
}
}
}
$HTML = #"
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
body{
background-color:white;
font-family:Arial;
font-size:8pt;
}
td,th{
border:1px solid black;
border-collapse:collapse;
}
th{
color:white;
background-color:black;
}
table, tr, td, th {
padding:5px;
margin: 0px;
}
table {
margin-left:50px;
width: 80%;
height:35%
}
.Warning {
background-color:yellow;
font-weight:bold
}
.Error {
background-color:#d9534f;
color:#ffffff;
}
</style>
</head>
<body>
<table>
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<tbody>
<tr>
<th>Name</th>
<th>Value</th>
<th>Status</th>
<th>Link</th>
</tr>
$($Sites | GetSiteStatus | %{
$item = $_
switch($_.Type){
"Good" {
"<tr class='Good'><td>$($item.Name)</td><td>$($item.Value)</td><td>$($item.Status)</td><td><a href='$($item.Value)'>$($item.Name)</a></td></tr>"
}
"Warning" {
"<tr class='Warning'><td>$($item.Name)</td><td>$($item.Value)</td><td>$($item.Status)</td><td><a href='$($item.Value)'>$($_item.Name)</a></td></tr>"
}
"Error" {
"<tr class='Error'><td>$($item.Name)</td><td>$($item.Value)</td><td>$($item.Status)</td><td><a href='$($item.Value)'>$($item.Name)</a></td></tr>"
}
}
})
</tbody>
</table>
</body>
</html>
"# | out-file $OutFile

force rowspan not to split other column data in new page

Currently i'm working on attendance report generation but now i face this problem i try every css print property but nothing works for me below the css code that i use
#printdata h1,h2,h3,h4,h5,h6{
text-align: center;
line-height: 0.1em;
text-transform: uppercase;
}
#printdata p{
font-size: 20px;
font-weight: bold;
text-align: center;
text-transform: uppercase;
}
#printdata table {
margin-top: 10px;
page-break-after:auto;
width:100%
}
#printdata tr{
page-break-inside: avoid;
-webkit-region-break-inside: avoid;
}
#printdata td{
page-break-inside:avoid;
page-break-after:auto;
padding: 16px 0px;
font-size: 12pt;
}
thead{
display:table-header-group;
}
tfoot{
display:table-footer-group;
}
Here my php code where i use rowspan on column 1 and 2
<tbody>
<?
if(count($this->employees) > 0)
{
$x = 0;
foreach ($this->employees as $key=>$employee)
{
?>
<tr>
<td rowspan="2"><? echo ++$x; ?></td>
<td rowspan="2" align="center"><? echo $employee->ticket_no; ?></td>
<td colspan="2"><? echo $employee->employee_name; ?></td>
<?
for($i=1;$i<=$days_in_month;$i++)
{
?>
<td align="center">
<?
if($employee->in_time[$i] == "" && $employee->out_time[$i] == "" && $employee->minutes_late[$i] == "" && $employee->gate_pass[$i] == "" && $employee->idle_booking[$i] == "" && $employee->minutes_early[$i] == "" && $employee->second_half_cl[$i] == "")
{
echo $employee->attendance[$i];
}
else
{
echo $employee->in_time[$i];
echo ($employee->out_time[$i] != "" ? $employee->out_time[$i] : "");
//echo ($employee->attendance[$i] != "" ? $employee->attendance[$i] : "");
echo ($employee->minutes_late[$i] != "" ? $employee->minutes_late[$i] : "");
echo ($employee->gate_pass[$i] != "" ? ($employee->minutes_late[$i] != "" ? " + " : "") . $employee->gate_pass[$i] : "");
echo ($employee->idle_booking[$i] != "" ? $employee->idle_booking[$i] : "");
echo ($employee->minutes_early[$i] != "" ? $employee->minutes_early[$i] : "");
echo ($employee->second_half_cl[$i] != "" ? $employee->second_half_cl[$i] : "");
//echo ($this->leaves[$i] != "" ? $employee->second_half_cl[$i] : "");
}
?>
</td>
<?
}
?>
<td colspan="2" align="center">A</td>
<td align="center">B</td>
<td colspan="2" align="center">C</td>
</tr>
<tr>
<td><? echo $employee->section; ?></td>
<td><? echo $employee->trade; ?></td>
<?
for($i=1;$i<=$days_in_month;$i++)
{
echo "<td align='center'>";
echo $i;
echo "</td>";
}
?>
<td align="center">1</td>
<td align="center">2</td>
<td align="center">3</td>
<td align="center">4</td>
<td align="center">5</td>
</tr>
<?
}
}
?
</tbody>
This is the result basically i get i just want to forcefully stop spliting rowspan in new page it would be great is its avoid split and print the whole row in new page
For better understanding check below image and any help would be appriciated
https://i.stack.imgur.com/tvkF5.png
Can you see if this works?
printdata table { page-break-inside:auto }
printdata table tr { page-break-inside:avoid;
page-break-after:auto }

Table cell td with max-width showing too much white space if line breaks

I am trying to make a table as small as possible. One cell may have more content then the desired width so I set "max-width". So in some cases the content will be broken into more lines, which is fine.
However, when a line breaks in two the table cell remains at the max-width, while it could be smaller if it would adjust to the now broken content.
Many words, easy to look at: http://jsfiddle.net/G3bcB/10/
<p>Too much white space:</p>
<table>
<tr>
<td class="leftcell">long texttext overflow</td>
<td>B</td>
<td>C</td>
</tr>
</table>
<p>Upper table could have same width:</p>
<table>
<tr>
<td class="leftcell">long texttext</td>
<td>B</td>
<td>C</td>
</tr>
</table>
table { width: auto; }
td { border: 1px solid black; }
td.leftcell { max-width: 100px; }
I am not sure if this is a feature of HTML, but to me it seems wrong.
Is it possible to make the field smaller (using standard css)?
You can't do this without Javascript. Fortunately it's not too complicated. I changed the class of the first cell to leftcell1 to distinguish it from the lower table and lengthened the string for demo purposes:
<td class="leftcell1">
long texttext overflow long overflow
</td>
Here's the updated jsFiddle.
And the javascript:
var el = $('.leftcell1');
//temporarily puts the text in the cell to measure it
function getWidth(el, txt) {
el.html(txt);
return el.css('width').replace('px', '');
}
//returns the string w/ the <br /> tags in the right place
function splitString(maxWidth) {
var txtArr;
var presentTxt = '';
var futureTxt = '';
var finalTxt = '';
//split the words up if longer than the max width
if (getWidth(el, el.html()) >= maxWidth) {
txtArr = el.html().split(' ');
//loop through the words and add them together
for (var i in txtArr) {
futureTxt += txtArr[i] + ' ';
//check if the string is longer than the max width
if (getWidth(el, futureTxt) > maxWidth) {
//It is. Add it to the final string with a <br />
//and chop off the trailing space
finalTxt += presentTxt.substring(0, presentTxt.length - 1) + '<br />';
futureTxt = presentTxt = txtArr[i] + ' ';
} else {
//it's not. Keep adding to it.
presentTxt = futureTxt;
}
}
} else {
finalTxt = el.html();
}
//if there is anything leftover in futureTxt add it to finalTxt
if (futureTxt != '') {
finalTxt += futureTxt;
}
return finalTxt;
}
el.html(splitString(100));

Resources