0

I want to create a document with serial barcode (10 per page) so I am using the code bellow to generate a barcode:

my_code = Code128(document)
my_code.save(document)

The result of this code is an svg picture...So I want to insert this svg picture into a table in docx file and I am using this piece of code for that:

doc = Document('assets/test.docx')
tables = doc.tables
p = tables[0].rows[1].cells[0].add_paragraph()
r = p.add_run()
r.add_picture('BL22002222.svg', width=Inches(3), height=Inches(1))
doc.save('assets/test.docx')

but it through this error:

docx.image.exceptions.UnrecognizedImageError

I want to generate a printed pages pdf or docx i don't care the most important is that it contain barcode

  • python-docx seems to have [issues with svg files](https://github.com/python-openxml/python-docx/issues/651). A workaround might be [converting the svg to emf](https://stackoverflow.com/questions/67672120/unable-to-insert-emf-into-word-using-python#answer-67793893) – herrstrietzel Apr 26 '22 at 19:13
  • is there another solution, I want to generate a printed pages pdf or docx i don't care the most important is that it contain barcode – user18954743 Apr 26 '22 at 22:13
  • Depending on your python barcode generating module: I'd try to check if there is a **png 1bit (black/white) output option**. In fact you don't need vector graphics for bar- or QRcodes due to their simplistic structure (a pixel based barcode will most likely also beat a vector based regarding file size). So try to embed a pre-generated (using some online generator) png barcode – jpeg is clearly inferior for this purpose. – herrstrietzel Apr 26 '22 at 23:25

0 Answers0