This repository has been archived by the owner on Mar 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
BannerSheet.py
122 lines (117 loc) · 6.67 KB
/
BannerSheet.py
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# BannerSheet.py
__version__ = "v20200801"
# Setups up BannerSheet Postscript File
from PJL_Commands.BannerSheetPS import bannerSheet
def banner_sheet(order):
"""
Generates A Custom Postscript Banner Sheet
Generates a custom banner sheet for running these jobs.
Outputted in front of each job before all the files get outputted.
Parameters:
order (object): The object for the current order.
Returns:
string: The path to the banner sheet file.
"""
OUTPUT_PATH = "".join([order.OD, '/', order.NAME, '/'])
NAME = "", "Print & Copy"
LOC = ""
try:
with open("Credentials/creds.txt") as f:
cred = f.readlines()
cred = [x.strip() for x in cred]
NAME = (str(cred[1]), str(cred[2]))
LOC = str(cred[3])
except:
print("Credential Failure")
MEDIA_COLOR = ("white", "blue", "yellow", "green", "pink",
"ivory", "gray", "buff", "goldenrod,", "red", "orange")
# Allows differnet color banner sheets. Common Pastel/Astrobrights Colors
banner_sheet_color = MEDIA_COLOR[6]
# Read in Template BannerSheet PostScript File with PJL Commands for Xerox D110 Printer
pjl_lines = bannerSheet.splitlines()
# Swap template color for color of choice
for i in range(len(pjl_lines)):
if str('<media-color syntax="keyword">') in str(pjl_lines[i]):
pjl_lines[i] = str.encode("".join([
'@PJL XCPT <media-color syntax="keyword">', banner_sheet_color, '</media-color>']))
# Get the nested dictionary for file names & page counts from main dictionary from JSON File
files_list = []
for i in range(len(order.FILES)):
files_list.append(("".join(["File ",
str(i+1), ": ", order.FILES[i].NAME[13:]]), "".join(["Page Count: ", str(order.FILES[i].PAGE_COUNT)]))) # Remove clutter from string
# Template Postscript information
POSTSCRIPT = (
"".join(['\n%!PS\n', '/Arial-BoldMT findfont 75 scalefont setfont\n', '95 725 moveto (',
NAME[0], ') show\n']),
"".join(['\n%!PS\n', '/Arial-BoldMT findfont 74 scalefont setfont\n', '85 650 moveto (',
NAME[1], ') show\n']),
"".join(['/Arial-BoldMT findfont 45 scalefont setfont\n']),
"".join(['20 595 moveto (Order Number: ',
order.NUMBER, ' ) show\n']),
"".join(['/Arial-BoldMT findfont 25 scalefont setfont\n']),
"".join(['20 565 moveto (', LOC, ' - Order Banner Sheet) show\n']),
"".join(['/ArialMT findfont 12 scalefont setfont\n']),
)
vertical_position = int(545)
# Create Banner Sheet file with Order Number and Name
with open("".join([OUTPUT_PATH, order.NUMBER, ' Banner ', order.FIRST_NAME, ' ', order.LAST_NAME, '.ps']), 'wb') as outfile:
# Export PJL Lines
for lines in pjl_lines:
outfile.write(lines + b"\n")
# Export Postscript Lines
for line in POSTSCRIPT:
outfile.write(str.encode(line))
outfile.write(str.encode("".join(['20 ', str(
vertical_position), ' moveto (', "Order Subject: ", order.SUBJECT, ' ) show\n'])))
vertical_position = int(vertical_position) - 17
outfile.write(str.encode("".join(['20 ', str(
vertical_position), ' moveto (', "Date Ordered: ", order.DATE, ' ) show\n'])))
vertical_position = int(vertical_position) - 17
outfile.write(str.encode("".join(['20 ', str(
vertical_position), ' moveto (', "Email: ", order.EMAIL, ' ) show\n'])))
vertical_position = int(vertical_position) - 17
outfile.write(str.encode("".join(['20 ', str(
vertical_position), ' moveto (', "Last Name: ", order.LAST_NAME, ' ) show\n'])))
vertical_position = int(vertical_position) - 17
outfile.write(str.encode("".join(['20 ', str(
vertical_position), ' moveto (', "First Name: ", order.FIRST_NAME, ' ) show\n'])))
vertical_position = int(vertical_position) - 17
outfile.write(str.encode("".join(['20 ', str(
vertical_position), ' moveto (', "Phone Number: ", order.PHONE, ' ) show\n'])))
vertical_position = int(vertical_position) - 17
outfile.write(str.encode("".join(['20 ', str(
vertical_position), ' moveto (', "Copies: ", str(order.COPIES), ' ) show\n'])))
vertical_position = int(vertical_position) - 17
outfile.write(str.encode("".join(['20 ', str(
vertical_position), ' moveto (', "Duplex: ", order.DUPLEX, ' ) show\n'])))
vertical_position = int(vertical_position) - 17
outfile.write(str.encode("".join(['20 ', str(
vertical_position), ' moveto (', "Collation: ", order.COLLATION, ' ) show\n'])))
vertical_position = int(vertical_position) - 17
outfile.write(str.encode("".join(['20 ', str(
vertical_position), ' moveto (', "Paper: ", order.PAPER, ' ) show\n'])))
vertical_position = int(vertical_position) - 17
outfile.write(str.encode("".join(['20 ', str(
vertical_position), ' moveto (', "Special Instructions: ", str(order.SPECIAL_INSTRUCTIONS), ' ) show\n'])))
vertical_position = int(vertical_position) - 17
outfile.write(str.encode("".join(['20 ', str(
vertical_position), ' moveto (', "Slip Sheets / Shrink Wrap: ", str(order.SLIPSHEETS), ' ) show\n'])))
vertical_position = int(vertical_position) - 17
outfile.write(str.encode("".join(['20 ', str(
vertical_position), ' moveto (', "Deliver To Name: ", order.DELIVER_TO_NAME, ' ) show\n'])))
vertical_position = int(vertical_position) - 17
outfile.write(str.encode("".join(['20 ', str(
vertical_position), ' moveto (', "Deliver To Address: ", str(order.DELIVER_TO_ADDRESS), ' ) show\n'])))
vertical_position = int(vertical_position) - 25
# Export Files & Page Counts
for items in files_list:
outfile.write(str.encode("".join(['20 ', str(vertical_position),
' moveto (', str(items[0]).replace("(", " ").replace(")", " ").split("', '")[0], ' ) show\n'])))
vertical_position = int(vertical_position) - 15
outfile.write(str.encode("".join(['20 ', str(vertical_position),
' moveto (', str(items[1]).replace("(", " ").replace(")", " ").split("', '")[0], ' ) show\n'])))
vertical_position = int(vertical_position) - 17
# Write Final Line of Postscript File
outfile.write(str.encode('showpage\n'))
# Return Location of Banner Sheet File
return "".join([OUTPUT_PATH, order.NUMBER, ' Banner ', order.FIRST_NAME, ' ', order.LAST_NAME, '.ps'])