adrianschlatter / ppf.datamatrix Goto Github PK
View Code? Open in Web Editor NEWPure-python package to generate data matrix codes.
License: Other
Pure-python package to generate data matrix codes.
License: Other
Trying to encode a character which is not supported by a codec will raise an exception (=> good). However, the error message is a bit misleading in some cases.
Example:
'ä'.encode('datamatrix.EDIFACT')
UnicodeEncodeError: 'ascii' codec can't encode character '\xe4' in position 0: ordinal not in range(128)
---------------------------------------------------------------------------
UnicodeEncodeError Traceback (most recent call last)
/InteractiveInput-1 in <module>
----> 1 'ä'.encode('datamatrix.EDIFACT')
~/Projects/ppf.datamatrix/src/ppf/datamatrix/codec_edifact.py in encode_to_edifact(msg)
46 elif n_rest == 1:
47 if len(msg) < 2:
---> 48 enc = (b'\xF0' + pack(msg.encode('ascii'), b'\x1F\x00\x00'))
49 else:
50 enc = (b'\xF0' +
UnicodeEncodeError: 'ascii' codec can't encode character '\xe4' in position 0: ordinal not in range(128)
Note that we are trying to encode in 'datamatrix.EDIFACT'. But the error message says there is a failure when encoding to 'ascii'. We should catch this exception and re-raise an exception that say 'ä' is an invalid datamatrix.EDIFACT character.
Similar things happen in other codecs.
hello, i want save the dm_result, as jpg or png.. what can i do? @adrianschlatter
currently missing while datamatrix-svg has it.
Hi Adrian,
I really appreciated how you built the package. I tested on Python Console of my Mac OS and it works fine.
The issue come when I want to use it in my flask app by importing this: from ppf.datamatrix import DataMatrix , Flask pop up the error: NO MODULE FOUND named ppf.
Why did you put a dot and really, how can I do to fix that. I'm stuck since your last release of this code.
Tthanks
Hello,
I have almost no knowledge in SVG.
I want to 3D print Datamatrix barcodes.
So the plan was to generate SVGs and then use them in FreeCAD or openscad to extrude them into 3D objects.
But in FreeCAD it shows up as horizontal lines and in openscad, it looks almost like a datamatrix, but it isn't.
I opened the file in Inkscape and it works fine there.
I guess this is a limitation of how the file is generated. Can you maybe explain why? Can this be changed? etc.
Here is the genrated SVG
And here the openscad extrude
I am doing a project for which I want to generate data-matrixes of 10x10, which stores six integers. In the webdemo, six digits results in a 10x10 data-matrix, but in this ported package, it returns a 12x12 data matrix. Do you perhaps have a fix for this? Thanks!
Right now, there seems to be a margin of 1px around the datamatrix when outputting to SVG. Would it be possible to make this optional? (happy to create a pull request)
Hello,
the SVG cannot be scaled via CSS since the path is absolute. If you add viewBox="0 0 W H" (e.g. viewBox="0 0 18 18" if the width and height is 18), scaling works very well.
Firstly, thank you for this excellent library. While attempting to implement a datamatrix code in labelprinterkit with this library, I encountered an issue.
This is a small example code:
from ppf.datamatrix import DataMatrix
dm = DataMatrix('Hello World!', rect=True)
with open('/tmp/test.svg', 'w') as fh:
fh.write(dm.svg())
I am using the current develop branch (a9e292c) on Python 3.11.4.
The code above gives this result:
My barcode reader is giving the following output: "Hello World!gmlqqy[)>�06���". As you can see, there is some garbage at the end of the line.
Generating the same string with the tools from https://www.bcgen.com/datamatrix-barcode-creator.html gives a bit different output:
Which is read fine by my barcode reader.
I don't know if this is a bug or if something is broken in my setup. Maybe someone can try to confirm this issue?
Structure is rather unsystematic currently.
pyproject.tomlize
Example code:
from ppf.datamatrix import DataMatrix
from cairosvg import svg2png
from IPython.display import Image, display
s = 'SD0000-REF-C0-I0'
myDataMatrix = DataMatrix(s).svg()
svg = svg2png(myDataMatrix,write_to=None,output_width=100,output_height=100)
display(Image(svg))
This image decodes to "SD0000-REF-C0-I0 U03" and some non-printable characters.
Expected result (from demo https://datalog.github.io/demo/datamatrix-svg/):
Which decodes correctly, with any message.
I noticed that a "small" change in message results in the correct datamatrix - 'SD0000-R-C0-I0' works well.
add one. Maybe the datamatrix in README?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.