mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-29 05:00:08 +02:00
Allow to generate multiple labels at once (multiple pages in 1 PDF file).
This commit is contained in:
parent
4c5820ee22
commit
e89cc4bb01
12 changed files with 389 additions and 228 deletions
|
@ -45,17 +45,35 @@ class LabelGenerator
|
|||
$this->labelHTMLGenerator = $labelHTMLGenerator;
|
||||
}
|
||||
|
||||
public function generateLabel(LabelOptions $options, object $element): string
|
||||
/**
|
||||
* @param LabelOptions $options
|
||||
* @param object|object[] $element An element or an array of elements for which labels should be generated
|
||||
* @return string
|
||||
*/
|
||||
public function generateLabel(LabelOptions $options, $elements): string
|
||||
{
|
||||
if (!$this->supports($options, $element)) {
|
||||
throw new \InvalidArgumentException('The given options are not compatible with the given element!');
|
||||
if (!is_array($elements) && !is_object($elements)) {
|
||||
throw new \InvalidArgumentException('$element must be an object or an array of objects!');
|
||||
}
|
||||
|
||||
if (!is_array($elements)) {
|
||||
$elements = [$elements];
|
||||
}
|
||||
|
||||
$elements_html = [];
|
||||
|
||||
dump($elements);
|
||||
|
||||
foreach ($elements as $element) {
|
||||
if (!$this->supports($options, $element)) {
|
||||
throw new \InvalidArgumentException('The given options are not compatible with the given element!');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$dompdf = new Dompdf();
|
||||
$dompdf->loadHtml($this->labelHTMLGenerator->getLabelHTML($options, $element));
|
||||
|
||||
$dompdf->setPaper($this->mmToPointsArray($options->getWidth(), $options->getHeight()));
|
||||
|
||||
$dompdf->loadHtml($this->labelHTMLGenerator->getLabelHTML($options, $elements));
|
||||
$dompdf->render();
|
||||
return $dompdf->output();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue