vCard QR code using Libre Office

Hi, is there any method to create a vCard QR code using Calc? As in, fill the columns with Name, Address, email, phone number, WhatsApp etc and get QR code for the same? Thanks.

I am using Ubuntu 22.04. I have Windows 10 as well if required.

In Ubuntu and Python is trivial.

sudo apt install libreoffice-script-provider-python
sudo apt install python3-pip
pip install --user segno
mkdir -p ~/.config/libreoffice/4/user/Scripts/python
vim ~/.config/libreoffice/4/user/Scripts/python/mymacros.py

In mymacros.py copy and paste:

import uno
from segno import helpers


def main():
    path = '/home/mau/my-vcard.svg'
    doc = XSCRIPTCONTEXT.getDocument()
    selection = doc.CurrentController.Selection
    data = {row[0]: row[1] for row in selection.DataArray}
    qrcode = helpers.make_vcard(**data)
    qrcode.save(path, scale=4)
    return

The field names should be exactly that vCard standar, see:
https://segno.readthedocs.io/en/latest/contact-information.html
And all data should be like text.

Select range…
image

And execute macro Tools… Run macro.
image

Good luck

2 Likes

→→

data = dict(selection.DataArray)

@elmau, thank you! I see very similar functionality for 1D barcodes available using python-barcode. And I need 1D barcodes right now. python-barcode uses Pillow for image creation. Before going down that rabbit hole, I thought I’d see if you know:

Is there a way to take the return from a call to create a new graphic in pillow (PIL.Image.Image object?) and add it directly to the current ODS as an image, rather than save it to an external file then load it back?

Yes, is possible.
You only need Pillow, if you want image in others formats than SVG.
Please, open new ask and I answer you in that.
image