-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdfplumber_grouping_and_photoshop.py
56 lines (49 loc) · 1.97 KB
/
pdfplumber_grouping_and_photoshop.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
import pdfplumber
import sys
import win32com.client
import os
filenamelist = sys.argv[1:]
filenamelist = ["etsy.pdf", "amazon.pdf"]
filltext = [[]]
filltextcurrent = 0
for filename in filenamelist:
with pdfplumber.open(filename) as currentfile:
firstpage = currentfile.pages[2].extract_text()
if firstpage != "":
if firstpage.split(" ")[0] == "Order":
pdftype = "etsy"
startstr = "Personalization:"
endstr = "Shop"
elif firstpage.split(" ")[0] == "Ship":
pdftype = "amazon"
else:
pdftype = "error"
for page in currentfile.pages:
pagetext = page.extract_text()
if len(filltext[filltextcurrent]) < 12:
if pdftype == "amazon":
filltext[filltextcurrent] += [pagetext[pagetext.find("Font Color: font (#000)")+len("Font Color: f (#000)"):pagetext.find("Grand total")]]
elif pdftype == "etsy":
filltext[filltextcurrent] += [pagetext[pagetext.find("Personalization:")+len("Personalization:"):pagetext.find("Do the green thing")]]
else:
filltext[filltextcurrent] += [""]
else:
filltextcurrent += 1
filltext.append([])
filltext[filltextcurrent] += ["test"]
else:
print("error 0")
print(filltext[0])
input()
# Open photoshop
psApp = win32com.client.Dispatch("Photoshop.Application")
batchcount = 0
for batch in filltext:
# Open template file
psApp.Open(r"C:\path\to\template.psd")
doc = psApp.Application.ActiveDocument
# Set text for all layers
for a in range(1, len(batch)):
doc.ArtLayers[str(a)].TextItem.contents = batch[a-1]
# Save as a new psd
doc.SaveAs(r"C:\path\to\batch"+str(batchcount)+".psd")