Tech/HowTo/PC Engines/labels
< Tech | HowTo | PC Engines
Jump to navigation
Jump to search
Source for https://lathama.net/labels/
- Should work on PHP7
- Download http://www.fpdf.org/ and extract to a directory called fpdf
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
if($_POST["print"])
{
require('fpdf/fpdf.php');
$width1 = 50;
$width2 = 100;
$height = 10;
$model = htmlspecialchars($_POST["model"]);
$hostname = htmlspecialchars($_POST["hostname"]);
$serial = htmlspecialchars($_POST["serial"]);
$mac1 = htmlspecialchars($_POST["mac1"]);
$mac2 = htmlspecialchars($_POST["mac2"]);
$mac3 = htmlspecialchars($_POST["mac3"]);
$pdf=new FPDF('P','mm','Letter');
$pdf->AddPage();
$pdf->SetAuthor('author');
$pdf->SetCreator('fpdf');
$pdf->SetMargins(10, 10);
$pdf->SetFont('Arial','B',14);
$pdf->SetAutoPageBreak(0);
$pdf->SetFillColor(240,240,240);
$pdf->SetXY(10, 10);
$pdf->Cell($width1,$height,'Model:','1',0,'R',1);
$pdf->Cell($width2,$height,$model,'1',1,'C',0);
$pdf->Cell($width1,$height,'Hostname:','1',0,'R',1);
$pdf->Cell($width2,$height,$hostname,'1',1,'C',0);
$pdf->Cell($width1,$height,'Serial:','1',0,'R',1);
$pdf->Cell($width2,$height,$serial,'1',1,'C',0);
$pdf->Cell($width1,$height,'Ethernet 1 MAC:','1',0,'R',1);
$pdf->Cell($width2,$height,$mac1,'1',1,'C',0);
$pdf->Cell($width1,$height,'Ethernet 2 MAC:','1',0,'R',1);
$pdf->Cell($width2,$height,$mac2,'1',1,'C',0);
$pdf->Cell($width1,$height,'Ethernet 3 MAC:','1',0,'R',1);
$pdf->Cell($width2,$height,$mac3,'1',1,'C',0);
$pdf->Cell($width1,$height,'USB:','1',0,'R',1);
$pdf->Cell($width2,$height,'2 x USB 3.0 Type A','1',1,'C',0);
$pdf->Cell($width1,$height,'Power:','1',0,'R',1);
$pdf->Cell($width2,$height,'2.5mm Center Positive 12v 2a','1',1,'C',0);
$pdf->Output();
}
}
else
{
$output = '<html><style>html{margin: 20px;font-size:16pt;}body{width: 300px; margin: auto;}dt{padding:5px;text-align:right;}</style><title>PC Engines Label Maker</title>';
$output .= '<body><form action="/labels/" method="post"><dl>';
$output .= '<input type="hidden" name="print" value="1" />';
$output .= '<dt><label for="model">Model: </label><input type="text" name="model" value="PC Engines APU2" /></dt>';
$output .= '<dt><label for="hostname">Hostname: </label><input type="text" name="hostname" value="host.example.com" /></dt>';
$output .= '<dt><label for="serial">Serial: </label><input type="text" name="serial" value="115200n8" /></dt>';
$output .= '<dt><label for="mac1">Eth1 MAC: </label><input type="text" name="mac1" value="12:34:56:78:90" /></dt>';
$output .= '<dt><label for="mac2">Eth2 MAC: </label><input type="text" name="mac2" value="12:34:56:78:90" /></dt>';
$output .= '<dt><label for="mac3">Eth3 MAC: </label><input type="text" name="mac3" value="12:34:56:78:90" /></dt>';
$output .= '<dt><input type="submit" value="print" /></dt></dl>';
$output .= '</form>';
$output .= '<p>Create PDF label for an PC Engines APU device</p>';
$output .= '';
$output .= '';
$output .= '</body>';
$output .= '</html>';
echo $output;
}
?>