-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPDF417.py
More file actions
69 lines (52 loc) · 1.72 KB
/
PDF417.py
File metadata and controls
69 lines (52 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
""" PDF417 Barcode Generator.
"""
import os
import tempfile
import binascii
from sii.lib.lib import syscall
from .Barcode import Barcode
class PDF417(Barcode):
"""0 0 moveto <{hexdata}> ({options}) /pdf417 /uk.co.terryburton.bwipp findresource exec"""
# % 0 -10 rmoveto (PDF417) show
def __init__(self, data, rows=None, columns=None):
self.data = data
self.data_hex = binascii.hexlify(data.encode('ISO-8859-1')).decode('utf8')
self.rows = rows
self.columns = columns
@property
def ps(self):
options = []
if self.rows:
options.append('rows={0}'.format(self.rows))
if self.columns:
options.append('columns={0}'.format(self.columns))
# We append the pdf417 call onto the read in library and return
ps_cmd = '\n\n'
ps_cmd += self.__doc__.format(
hexdata = self.data_hex,
options = ','.join(options)
)
return self.__lib__ + ps_cmd
@property
def eps(self):
return self._eps()
@property
def eps_filepath(self):
return self._eps(return_path=True)
def _eps(self, return_path=False):
tmp = tempfile.TemporaryDirectory()
ps_fname = os.path.join(tmp.name, 'barcode.ps')
eps_fname = os.path.join(tmp.name, 'barcode.eps')
result = None
with open(ps_fname, 'w') as fh:
fh.write(self.ps)
converter = syscall.Ps2Eps()
converter.call(ps_fname)
if return_path is True:
return eps_fname
else:
with open(eps_fname, 'rb') as fh:
result = fh.read()
tmp.cleanup()
return result