-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCreateBarcode.py
More file actions
82 lines (70 loc) · 3.82 KB
/
CreateBarcode.py
File metadata and controls
82 lines (70 loc) · 3.82 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
70
71
72
73
74
75
76
77
78
79
80
81
82
#
# (c) 2022 Hyland Software, Inc. and its affiliates. All rights reserved.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#****************************************************************************
#* Document Filters Example - Create a barcode image.
#****************************************************************************/
import os, sys, argparse, traceback, DocumentFiltersSample
from DocumentFilters import *
api = DocumentFilters()
BarcodeMap = {
"qr": DocumentFilters.Annotations.QrCode,
"dm": DocumentFilters.Annotations.DataMatrix,
"pdf417": DocumentFilters.Annotations.PDF417,
"code39": DocumentFilters.Annotations.Code39,
"code93": DocumentFilters.Annotations.Code93,
"code128": DocumentFilters.Annotations.Code128,
"gs1-128": DocumentFilters.Annotations.GS1_128,
"aztec": DocumentFilters.Annotations.Aztec,
}
def GetCanvasType(filename):
ext = os.path.splitext(filename)[1].lower()
if (ext == ".pdf"): return IGR_DEVICE_IMAGE_PDF
if (ext == ".tif"): return IGR_DEVICE_IMAGE_TIF
if (ext == ".xps"): return IGR_DEVICE_IMAGE_XPS
if (ext == ".html"): return IGR_DEVICE_HTML
if (ext == ".xml"): return IGR_DEVICE_XML
if (ext == ".png"): return IGR_DEVICE_IMAGE_PNG
if (ext == ".jpg"): return IGR_DEVICE_IMAGE_JPG
if (ext == ".bmp"): return IGR_DEVICE_IMAGE_BMP
raise Exception(f"I don't know how to create {ext} files")
def Process(args, console):
barcode = BarcodeMap[args.type]()
barcode.Content = args.text
barcode.Caption = args.caption
barcode.Rect = DocumentFilters.AnnotationRect.FromLTRB(10, 10, args.width - 10, args.height - 10)
with api.MakeOutputCanvas(args.output, GetCanvasType(args.output)) as canvas:
canvas.BlankPage(args.width, args.height)
canvas.Annotate(barcode)
console.write(f"Saved {args.output}")
try:
parser = argparse.ArgumentParser(description='Get Document Type')
parser.add_argument('text', metavar='text', type=str, nargs='?', help='Text to encode into barcode')
parser.add_argument('-o', '--output', dest='output', action='store', default="output.png", help='Output file name to create')
parser.add_argument('-t', '--type', dest='type', action='store', default="qr", help=f'Type of barcode to create ({(", ".join(BarcodeMap.keys()))})')
parser.add_argument('--width', dest='width', action='store', type=int, default=250, help='Width of barcode to create')
parser.add_argument('--height', dest='height', action='store', type=int, default=250, help='Height of barcode to create')
parser.add_argument('--caption', dest='caption', action='store', default=None, help='Caption to apply to barcode')
parser.add_argument('-l', '--library', dest='library_path', action='store', help='Path to the Document Filters libraries')
parser.add_argument('--license-key', dest='license_key', action='store', help='License key for Document Filters')
args = parser.parse_args()
# Prepare and Initialize Engine
DocumentFiltersSample.InitializeAPI(api, args)
# Get Extractor and Convert Document
Process(args, sys.stdout)
except Exception as e:
trace_info = traceback.extract_tb(e.__traceback__)
sys.stderr.write(f'{e}\n => {trace_info[-1].filename}:{trace_info[-1].lineno}\n')
raise
exit(1)