0

help me please( I can't generate DataMatrix with GS1 symbol(FNC1) in python. when I just try the below code I can't get symbol gs1 in the screen

from ppf.datamatrix import DataMatrix
data = '0104680059740223213(OkNQCgC*qXF91KZF092gSnuwHu7c3KkrgPhR7eWzfH5/Qg=gSnuwHu7c3KkrgPhR7eWzfH5/Qg=gSnuwHu7c3KkrgPhR7eWzfH5/Qg=gSnu'
myDataMatrix = DataMatrix(data)
myDataMatrix

enter image description here

3 Answers 3

1

The solution is using a library which supports GS1 DataMatrix codes and then create a file out of it.

The one for you is treepoem, which identifies the values, adds FNC1 as a starting character and GS characters where needed.

Here is a simple script to generate correctly, you might have to adjust the data content and options to your needs.

from treepoem import generate_barcode
from PIL import Image

def generate_and_print(gtin, serial_number, expiry_date, batch_number):
    # Generate datamatrix
    datamatrix = generate_barcode(
        barcode_type='gs1datamatrix',
        data=f"(01){gtin}(21){serial_number}(17){expiry_date}(10){batch_number}",
        options={"parsefnc": True, "format": "square", "version": "26x26"})
    
    # Resize datamatrix to desired size
    dm_size_px = (120, 120)
    datamatrix = datamatrix.resize(dm_size_px, Image.NEAREST)

    # Create white picture
    picture_size_px = (200, 200)
    picture = Image.new('L', picture_size_px, color='white')

    # Position the datamatrix
    barcode_position_px = (40, 40)
    picture.paste(datamatrix, barcode_position_px)

    # Save the image
    picture.save("datamatrix.png")

gtin = "01234567890128"
serial_number = "01234567891011"
expiry_date = "250731"
batch_number = "DATAMATRIXTEST"

generate_and_print(gtin, serial_number, expiry_date, batch_number)
Sign up to request clarification or add additional context in comments.

Comments

0

You are printing out the DataMatrix object. There is no reason for an image to show up. The call:

myDataMatrix.svg()

will return the content of the svg file with the datamatrix. You can save the contents into a file and view it, for example in a web browser.

with open("myfilename.svg", "w") as f:
    f.write(myDataMatrix.svg())

If you are refering to the ppf.datamatrix homepage, which seems to suggest, that executing myDataMatrix should somehow print out the code: They probably use Jupyter notebook ot ipython.

1 Comment

Thank u) but u don't understand my question) I can get and see DataMatrix(DM) but my DM does not include the GS1 symbol(symbol in the data what I need to change DM, original data where u can see GS1 symbol on screen: i.sstatic.net/IiwWg.png ) When I search I find this page datamark.by/voprosy-otvety/gs1-datamatrix but I don't have any idea how I can do it(
0

You might have to find the encoder in the module you used and add chr(232) which is the FNC1 symbol at the beginning of the codewords. Then all of your datamatrix will be in GS1 format.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.