endroid / qr-code

QR Code Generator
https://endroid.nl
MIT License
4.41k stars 725 forks source link

Add Link option to PdfWriter #400

Closed laurentmuller closed 1 year ago

laurentmuller commented 1 year ago

When output the qr-code within the PdfWriter, it will be nice to add a link to the generated image.

Based on the official documentation, a method exist to set a link:

Link(float x, float y, float w, float h, mixed link)

I propose to add a new option to the writer:

    public const WRITER_OPTION_LINK = 'link';

This option can be a URL or identifier returned by AddLink().

It's just a matter of calling 2 functions:

public function write(...): ResultInterface {
    ...
    if (isset($options[self::WRITER_OPTION_LINK])) {
        $link = $options[self::WRITER_OPTION_LINK];
        $fpdf->Link($x, $y, $x + $matrix->getOuterSize(), $y + $matrix->getOuterSize(), $link);
    }
    ...
}