A font-based barcode in LibreOffice Calc

Making Barcodes in LibreOffice Calc with Fonts

An example of making barcodes in Calc with plain-DLL version of StrokeScribe barcode generator and specialized TrueType barcode fonts.

How to Proceed

Building a Barcode Formula

1. Create a new macro module. Press Alt + F11. Select My Macros -> Standard and press New:

Creating a Basic macro in Calc

2. Paste the following code into the module.

' Function definitions for 64-bit Calc Private Declare Function Initialize Lib "StrokeScribeDL64.dll" Alias "Initialize" () as Long Private Declare Function SetTextProp Lib "StrokeScribeDL64.dll" Alias "SetTextPropA" (ByVal name as String, ByVal val as String) as Long Private Declare Function SetLongProp Lib "StrokeScribeDL64.dll" Alias "SetLongPropA" (ByVal name as string, ByVal val as Long) as Long Private Declare Function GetFontOut Lib "StrokeScribeDL64.dll" Alias "GetFontOutA" (ByRef val as String, ByRef len as Long) as Long ' Barcode type definitions. More constants. Const QRCODE = 25 Const DATAMATRIX = 8 Const CODE128 = 5 Const PDF417 = 6 Public function CreateBarcodeFont(data as String) as String Dim rc as Long rc = Initialize () if rc<>0 then Print ("Initialize() error: " & rc) exit function endif rc = SetLongProp ("Alphabet", QRCODE) ' or DATAMATRIX if rc<>0 then Print ("SetLongProp() error: " & rc) exit function endif rc = SetTextProp ("Text", data) if rc<>0 then Print ("SetTextProp() error: " & rc) exit function endif Dim fontString as String * 8000 Dim fontLen as long fontLen = Len (fontString) rc =GetFontOut (fontString, fontLen) if rc<>0 then Print ("GetFontOut() error: " & rc) exit function endif CreateBarcodeFont = fontString end function

3. Make a large cell that will fit the barcode.

A group of merged cells

4. Format the cell with the StrokeScribe 2D font.

Adding a barcode formula into a cell

5. Paste the following into the formula field:

= CREATEBARCODEFONT("ABC")

6. Center the barcode in the cell:

Formatting the barcode

How to Customize the Barcode

Setting the QR CODE Error Correction Level

rc = SetLongProp("Alphabet", QRCODE) rc = SetLongProp("QrEcl", 3) 'ECL=H

Producing Pdf417 Barcodes with Fixed Number of Rows or Columns

rc = SetLongProp("Alphabet", PDF417) rc = SetLongProp("PDF417Cols", 4) rc = SetLongProp("PDF417Rows", 15)

Forcing the Minimum Matrix Size of DATA MATRIX Barcodes

rc = SetLongProp("Alphabet", DATAMATRIX) rc = SetLongProp("DataMatrixMinSize", 40)