【发布时间】:2020-02-22 00:12:33
【问题描述】:
我想打印出结果可以是每列有固定的行,就像每行有4个元素
我的代码:
<!DOCTYPE html>
<html>
<head>
<title>Print your data</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
* {
font-family: Arial;
}
p.inline {
display: inline-block;
}
span {
font-size: 13px;
}
.grid-container {
position: relative;
display: inline-block;
}
.a {
position: relative;
display: inline-block;
margin: 15px;
}
.print {
margin-top: 10px;
background-color: navy;
color: white;
}
.print:hover {
color: white;
background-color: black;
}
</style>
<style type="text/css" media="print">
@page
{
size: auto; /* auto is the initial value */
margin: 1mm; /* this affects the margin in the printer settings */
}
.grid-container {
position: relative;
display: inline-block;
}
.a {
position: relative;
display: inline-block;
margin: 15px;
}
.print {
display: none;
}
</style>
</head>
<body>
<div class="col text-center">
<button onclick="window.print();" class="print btn btn-lg">Print your data</button>
</div>
<div style="margin: 1%">
<?php
require 'vendor/autoload.php';
$row = 1;
if (($csvfile = fopen($_FILES['file']['tmp_name'], "r")) !== FALSE) {
while (($csvdata = fgetcsv($csvfile, 1000, ",")) !== FALSE) {
$colcount = count($csvdata);
//Skip the CSV first line, start read from second line
if($row == 1) {
$row++; continue;
}
if($colcount!=5) {
$error = 'Column count incorrect';
} else {
$imageData = base64_encode(file_get_contents($csvdata[4]));
$generator = new \Picqer\Barcode\BarcodeGeneratorPNG();
echo '<div class="grid-container">';
echo '<div class="a">
<img src="data:image;base64,'.$imageData.'" width="50"/>
<div><b>Item: '.$csvdata[0].'</b></div>
<div>
<img src="data:image/png;base64,' . base64_encode($generator->getBarcode("$csvdata[1]", $generator::TYPE_CODE_128)) . '"/>
<div><b>'.$csvdata[1].'</b></div>
</div>
<span><b>Price: '.$csvdata[2].'</b></span>
<div>
<span><b>Desc: </b>'.$csvdata[3].'</span>
</div>
</div></div>';
}
}
fclose($csvfile);
}
?>
</div>
</body>
</html>
现在打印结果:
我想要打印结果:
我在网上查了这个例子,但大多数例子都有不同的<tr>标签,但我的不像表格,我只有一个值要显示。
那么,在这种情况下,我怎样才能使打印布局固定每个元素的宽度,并且可以固定每行元素的数量?
【问题讨论】:
标签: php html css layout printing