Skip to content

Commit

Permalink
Add support for label in the PDF writer.
Browse files Browse the repository at this point in the history
Does not support setting a custom font yet.
  • Loading branch information
thijskh committed Dec 4, 2020
1 parent 43b3695 commit fe60861
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Writer/FpdfWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,15 @@ public function writeString(QrCodeInterface $qrCode): string
}

$label = $qrCode->getLabel();
if (null !== $label) {
throw new \InvalidArgumentException('The fpdf qr writer doesn\'t support a label.');
}
$labelHeight = $label !== null ? 30 : 0;

$data = $qrCode->getData();
$options = $qrCode->getWriterOptions();

$fpdf = new \FPDF(
'P',
$options[self::WRITER_OPTION_MEASURE_UNIT] ?? 'mm',
[$data['outer_width'], $data['outer_height']]
[$data['outer_width'], $data['outer_height'] + $labelHeight]
);
$fpdf->AddPage();

Expand Down Expand Up @@ -86,6 +84,12 @@ public function writeString(QrCodeInterface $qrCode): string
);
}

if (null !== $label) {
$fpdf->setY($data['outer_height'] + 5);
$fpdf->SetFont('Helvetica', null, $qrCode->getLabelFontSize());
$fpdf->Cell(0, 0, $label, 0, 0, strtoupper($qrCode->getLabelAlignment()[0]));
}

return $fpdf->Output('S');
}

Expand Down

0 comments on commit fe60861

Please sign in to comment.