-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquiz.py
More file actions
96 lines (51 loc) · 1.59 KB
/
Copy pathquiz.py
File metadata and controls
96 lines (51 loc) · 1.59 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
83
84
85
86
87
88
89
90
91
92
93
import pymupdf
print("Quiz Maker\n")
doc = pymupdf.open()
y_offset = 100
qheight = 200
doc.new_page()
pgno = 0
page = doc[pgno]
ocg_xref = doc.add_ocg("Answers",on=False)
page.insert_text(pymupdf.Point(300,50),"Quiz",fontsize=22)
while(True):
#global y_offset
#global pgno
#global page
#global doc
qtxt = input("Question text: ")
page.insert_text(pymupdf.Point(50,y_offset),qtxt,fontsize=12)
widget = pymupdf.Widget()
widget.field_type = 4
widget.field_name = f"question_{y_offset}"
widget.rect = pymupdf.Rect(50,y_offset+20,page.rect.x1-50,y_offset+100)
options = []
cnt = int(input("Number of items? "))
for opt in range(0,cnt):
optxt = input("Option: ")
options.append(optxt)
widget.choice_values = options
widget.text_fontsize = 12
try:
annot = page.add_widget(widget)
print("xref:",widget.xref)
except ValueError:
print("ERROR: Could not add widget (page.add_widget(): Bad xref) #1")
except:
print("ERROR: Could not add widget")
anstxt = input("Answer:")
page.insert_text(pymupdf.Point(50,y_offset+120),anstxt,fontsize=12,oc=ocg_xref)
more = input("Add more questions? (y/n): ").strip().lower() == "y"
if(more):
y_offset += qheight
if(y_offset + qheight > page.rect.y1):
doc.new_page()
pgno += 1
page = doc[pgno]
#add_question()
else:
break
#add_question()
exported = input("Exported file: ")
doc.ez_save(exported)
doc.close()