Print bar code label from libre base form

Hello,

I have a libre base form, from which I would like to print a barcode label for the ID whose record is displayed on the screen.

for example:
person id 1234567A (print barcode label for this id from the form)

Any help/suggestion would be appreciated.

Many thanks.

How to do this depends a lot upon what you know and how you want this to be actually done.

Are you going to print this using Report Builder or Writer or even something else? Do you want this to print immediately by, let’s say, pressing a button on the form? Are you knowledgable in programming macros?

You can add a boolean field to the record for print selection. Then create a query to select all records with this field ON and use that for wherever the printing will occur. After printing, the flag must be cleared.

Instead of setting a new field, possibly use a table filer record to store the data for this ID & base the query upon that.

In a macro, the button could activate the writing of this data to a temp file which is passed on to the printing program and the process started by the macro.

There are probably other possibilities but again it depends upon just how you want it to work and your abilities to complete this, especially concerning macro coding.

Edit:

Having presented multiple ways in my answer to print, it is not clear why you posted the comment.

Just to be clear, printing directly from the form would require you to create a macro. Since you state you don’t have any macro experience, the next easiest way is to print based on a parameter input for a query. The query is used as input to Report Builder (and again no mention of how you actually wanted to print even after asking in answer).

The report on the sample is simply printing the bar code field. There is no specific format since the label type and such are determined by you. To run the demo, there have been two records entered into the table - ID = 0 & ID = 1. In the Reports section, double click on BarcodeLabel. A Parameter Input dialog will pop up. In the Value field, enter 0 or 1 (record ID to select). On selecting OK button (Enter will do) the “Label” will pop up ready to be printed.

All of this is in the LO Base documentation found here.

Sample: BarcodePrintSample.odb

I did forget to mention - the odb does not carry the special bar code font with it. So first edit the Report and chage the field containing the bar code to use the font you installed on your system. The same can be said of the form I have on the sample.

Edit:

To avoid possible confusion, this next sample is the same as the first except where bar codes appear in the first, this one displays actual text.

Sample 2 - BarcodePrintSample (copy).odb

Without the ability to write the code (which you need to understand in order to make future modifications) printing immediately from a button can’t be done.

I believe you first task would actually get LO to print a bar code label with fictitious data. I believe you will need to use an extension or special character set to do so. This is not a built in function.

Here is a possible extension - click here.

Another - click here.

Thank you all for your suggestions/ideas.

I have managed to download free barcode fonts and I am able to see them in the base form. I still need to print just the barcode for the record being displayed on screen. Any ideas on how to do this?

Many thanks

Thank you for the quick response.

I have created simple data entry forms in libre base but nothing fancy and I do not have enough knowledge of programming or writing a macro.

I like the idea of printing the barcode label immediately by pressing a button on the form. This is what I had in mind. But don’t know how to do that.

Any help on how to do this would be very welcome.

Please use comments to reply to an answer.

IMO the easiest and best way to solve this problem is to install a barcode font. Then the only thing you have to figure out is:

  1. which kind of barcode to use (fx. Code 39)
  2. which character size it has to be so your scanner(s) can read the result of your printer(s)

This way you are able to generate barcodes in all software under your OS, not only LO Base.
Also you are completely free to add readable elements to the same label by switching to a human readable typeface.

There are two distinct jobs:

  1. Create a barcode label based on some info

  2. Print that label

    SUB all_in_one()
    DIM sText AS STRING
    DIM oDoc AS OBJECT
    sText = “12345678”
    oDoc = CreateADoc()
    PrintTextInDoc(sText, oDoc)
    PrintDocToPrinter(oDoc)
    oDoc.close(False)'Do not save it
    END SUB

    REM create here the label
    SUB PrintTextInDoc(sText AS STRING, oDoc AS OBJECT)
    DIM oNewDocVC AS OBJECT
    oNewDocVC = oDoc.CurrentController.getViewCursor 'Create View Cursor for this document
    'HERE you can change the font to some barcodefont if you want
    'Or make the barcode font the default font…

     '"Poke" the text to document 
     oNewDocVC.String = sText
    

    END SUB

    FUNCTION CreateADoc() AS OBJECT
    Dim FileProperties(0) As New com.sun.star.beans.PropertyValue
    DIM oDoc AS OBJECT
    FileProperties(0).Name = “Hidden”
    FileProperties(0).Value = FALSE 'True to create a hidden doc
    'load a doc with barcode font as default font
    'defaultdoc = “C:\mypathtodefaults\barcode.odt”
    'sURLofDOC = ConvertToURL(defaultdoc)
    'oDoc = starDesktop.loadComponentFromURL(sURLofDOC, “_blank”, 0, FileProperties())
    'OR load an empty doc
    oDoc = starDesktop.loadComponentFromURL(“private:factory/swriter”, “_blank”, 0, FileProperties())
    'Return oDoc
    CreateADoc = oDoc
    END FUNCTION

    SUB PrintDocToPrinter(oDoc AS OBJECT)
    Dim printopts(0) As New com.sun.star.beans.PropertyValue
    printopts(0).Name = “Wait”
    printopts(0).Value = True
    'Will print directly to default printer
    oDoc.print(printopts)
    END SUB