This is a Label wrapper for TCPDF.
Inspired by: https://github.com/Uskur/PdfLabel
This class extends the TCPDF class whose API is described here.
<?php declare(strict_types=1);
use FromHome\Pdf\Label;
$pdf = Label::newFromLabelType(Label::TYPE_L7161);
for($i= 0; $i < $pdf->getLabelsCount(); $i++)
{
$pdf->addLabel('Label text ' . $i);
}
$pdf->save('/path/to/Labels.pdf');
Have a look at the LABELS
class constant in the Label class for all available, pre-defined formats.
<?php declare(strict_types=1);
use FromHome\Pdf\Label;
$formatDefinition = [
'paper-size' => 'A4',
'unit' => Label::UNIT_MILLIMETER,
'marginLeft' => 7,
'marginTop' => 10.5,
'NX' => 2,
'NY' => 2,
'SpaceX' => 0,
'SpaceY' => 0,
'width' => 98,
'height' => 138,
'cutLines' => true,
];
$pdf = Label::newFromFormatDefinition($formatDefinition);
for($i= 0; $i < $pdf->getLabelsCount(); $i++)
{
$pdf->addLabel('Label text ' . $i);
}
$pdf->save('/path/to/Labels.pdf');
$pdf->save('/path/to/Labels.pdf');
$pdf->serveInline('Labels.pdf');
$pdf->serveAsDownload('Labels.pdf');
$content = $pdf->getContent();
You can customize the document setup, header and footer by extending from the Label class as follows:
<?php
use FromHome\Pdf\Label;
final class MyLabel extends Label
{
public function setUpDocument() : void
{
# setup stuff like default font and font-size here
}
public function Header() : void
{
# Create a custom header here
# See: https://tcpdf.org/examples/example_003/
}
public function Footer() : void
{
# Create a custom footer here
# See: https://tcpdf.org/examples/example_003/
}
}