Commit 718a48ae authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

add an external method to generate barcode image.

parent c932a5ad
def generateBarcodeImage(self, barcode_type, data):
# huBarcode's DataMatrix support has limitation for data size.
# huBarcode's QRCode support is broken.
# more 1-D barcode types can be added by pyBarcode library.
barcode_type = barcode_type.lower()
if barcode_type == 'datamatrix':
from subprocess import Popen, PIPE
process = Popen(['dmtxwrite'],
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
close_fds=True)
output, error = process.communicate(input=data)
elif barcode_type == 'ean13':
from hubarcode.ean13 import EAN13Encoder
encoder = EAN13Encoder(data)
output = encoder.get_imagedata()
elif barcode_type == 'code128':
from hubarcode.code128 import Code128Encoder
encoder = Code128Encoder(data)
output = encoder.get_imagedata()
elif barcode_type == 'qrcode':
import qrcode
from cStringIO import StringIO
fp = StringIO()
img = qrcode.make(data)
img.save(fp, format='png')
fp.seek(0)
output = fp.read()
else:
raise NotImplementedError, 'barcode_type=%s is not supported' % barcode_type
RESPONSE = self.REQUEST.RESPONSE
RESPONSE.setHeader('Content-Type', 'image/png')
RESPONSE.setHeader('Content-Length', len(output))
return output
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>generateBarcodeImage</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>BarcodeUtils</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_generateBarcodeImage</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
2012-04-10 Kazuhiko
* add an external method to generate barcode image.
2011-11-11 arnaud.fontaine 2011-11-11 arnaud.fontaine
* Fix document conversion not being performed when data is set directly. * Fix document conversion not being performed when data is set directly.
......
1019 1020
\ No newline at end of file \ No newline at end of file
BaseMigration BaseMigration
\ No newline at end of file BarcodeUtils
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment