Beispiel #1
0
    def _qr_xobject(self):
        qr = qrcode.QRCode()
        qr.add_data(self.url)
        qr.make()

        img = qr.make_image(image_factory=PdfStreamQRImage)
        command_stream = img.render_command_stream()

        bbox_size = (qr.modules_count + 2 * qr.border) * qr.box_size
        qr_xobj = init_xobject_dictionary(command_stream, bbox_size, bbox_size)
        qr_xobj.compress()
        return self.writer.add_object(qr_xobj), bbox_size
Beispiel #2
0
    def as_form_xobject(self) -> StreamObject:
        """
        Render the object to a form XObject to be referenced by another
        content stream. See ISO 32000-1, § 8.8.

        *Note:* Even if :attr:`writer` is set, the resulting form XObject will
        not be registered. This is left up to the caller.

        :return:
            A :class:`~.generic.StreamObject` instance representing
            the resulting form XObject.
        """
        from pyhanko.pdf_utils.writer import init_xobject_dictionary
        command_stream = self.render()
        return init_xobject_dictionary(
            command_stream=command_stream, box_width=self.box.width,
            box_height=self.box.height,
            resources=self._resources.as_pdf_object()
        )