-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path09_graphic.py
61 lines (48 loc) · 1.93 KB
/
09_graphic.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
from appscript import *
indd = app("Adobe InDesign 2022")
doc = indd.make(new=k.document)
page1 = doc.pages[1]
# add a rectangle with properties
rectangle = page1.make(new=k.rectangle,
with_properties={
k.geometric_bounds: [20, 20, 100, 100],
k.stroke_weight: 0.5
})
print(rectangle.class_()) # k.rectangle
# image path: must be a full path
img = "/Users/***/Desktop/test.png"
# img = "/Users/***/Desktop/test.pdf" # place a pdf file(1st page)
# place a image to rectangle
# rectangle.place(img) # Error!
rectangle.place(mactypes.Alias(img))
# rectangle.place(mactypes.File(img)) # OK
# set fit option
rectangle.fit(given=k.proportionally)
# set opacity to image
rectangle.transparency_settings.blending_settings.opacity.set(80)
# rotate rectangle/image
# rectangle.rotation_angle.set(-45) # rotate rectangle
# rectangle.graphics[1].rotation_angle.set(-45) # rotate 1st graphic
# get file path
file_path = rectangle.graphics[1].item_link.file_path.get()
print("file_path: ", file_path) # Macintosh HD:Users:***:Desktop:test.png
# get parent layer name
layer_name = rectangle.graphics[1].item_layer.name.get()
print("layer_name: ", layer_name) # レイヤー 1/Layer 1
# add caption(file path) below image
b = rectangle.visible_bounds.get()
bounds = [b[2], b[1], b[2] + 10, b[3]]
page1.make(new=k.text_frame,
with_properties={
k.visible_bounds: bounds,
k.contents: file_path
})
# add a QR code
rectangle2 = page1.make(new=k.rectangle,
with_properties={
k.geometric_bounds: [20, 120, 50, 150], # w=h=30
k.fill_color: "Paper",
k.stroke_color: "None",
k.stroke_weight: 0,
})
rectangle2.Create_Plain_Text_QR_Code(plain_text="https://www.autodtp.app")