-
Notifications
You must be signed in to change notification settings - Fork 0
/
MakeSubjectPDFs.java
248 lines (217 loc) · 11.9 KB
/
MakeSubjectPDFs.java
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import com.opencsv.CSVReader;
import java.io.*;
import java.util.*;
import com.itextpdf.text.Chapter;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Section;
import com.itextpdf.text.pdf.CMYKColor;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.BaseFont;
public class MakeSubjectPDFs{
public static void main(String [] args) {
//initialize input reader
InputStreamReader isr;
BufferedReader in;
isr = new InputStreamReader( System.in );
in = new BufferedReader( isr );
List<List<String[]>> Data = new ArrayList<List<String[]>>();
List<String[]> Physics = new ArrayList<String[]>();
List<String[]> Mathematics = new ArrayList<String[]>();
List<String[]> Biology = new ArrayList<String[]>();
List<String[]> Chemistry = new ArrayList<String[]>();
List<String[]> EarthSpace = new ArrayList<String[]>();
List<String[]> Energy = new ArrayList<String[]>();
String foo;
int names = -1; //whether or not to include names when listing quetions: -1 -> initialized, 0 -> no, 1 -> yes
System.out.println("Do you wish to print names?");
while (names < 0) {
System.out.print("Please enter a valid answer (\"y\" or \"n\"): ");
try {
foo = in.readLine();
if(foo.equals("n")) names = 0;
if(foo.equals("y")) names = 1;
}
catch ( IOException e ) {names = -1;}
catch ( NumberFormatException e) {names = -1;}
}
try {
CSVReader reader = new CSVReader(new InputStreamReader(new FileInputStream("Questions.csv"), "UTF-8"));
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
//choose which List to add the Question Pairs to
switch(nextLine[2]){
case "Physics":
Physics.add(nextLine);
break;
case "Chemistry":
Chemistry.add(nextLine);
break;
case "Mathematics":
Mathematics.add(nextLine);
break;
case "Earth and Space Science":
EarthSpace.add(nextLine);
break;
case "Energy":
Energy.add(nextLine);
break;
case "Biology":
Biology.add(nextLine);
break;
default:
break;
}
}
//Add the individual Lists to the main Data List
Data.add(Physics);
Data.add(Mathematics);
Data.add(Biology);
Data.add(Chemistry);
Data.add(EarthSpace);
Data.add(Energy);
} catch (IOException e){
}
//Writing PDFs
try
{
//Font stuff
FontFactory.register("fonts/ArialUnicode.ttf","ArialUnicodeMS");
Font title = FontFactory.getFont("ArialUnicodeMS",BaseFont.IDENTITY_H,BaseFont.EMBEDDED, 10, Font.BOLD);
Font bigTitle = FontFactory.getFont("ArialUnicodeMS",BaseFont.IDENTITY_H,BaseFont.EMBEDDED, 12, Font.BOLD);
Font header = FontFactory.getFont("ArialUnicodeMS",BaseFont.IDENTITY_H,BaseFont.EMBEDDED, 14, Font.BOLD);
Font body = FontFactory.getFont("ArialUnicodeMS",BaseFont.IDENTITY_H,BaseFont.EMBEDDED, 10, Font.NORMAL);
/*
* THESE FONTS did not work with unicode :(
Font title = FontFactory.getFont(FontFactory.COURIER, 10, Font.BOLD, new CMYKColor(255, 255, 255, 0));
Font bigTitle = FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLD, new CMYKColor(255, 255, 255, 0));
Font body = FontFactory.getFont(FontFactory.COURIER, 10, Font.NORMAL, new CMYKColor(255, 255, 255, 0));
*/
for(int j = 0; j < Data.size(); j++){
Document document = new Document();
List<String[]> Subject = Data.get(j);
String pdfName="";
String subjectName="";
switch(j){
case 0:
pdfName = "Physics.pdf";
subjectName = "PHYSICS";
break;
case 1:
pdfName = "Mathematics.pdf";
subjectName = "MATHEMATICS";
break;
case 2:
pdfName = "Biology.pdf";
subjectName = "BIOLOGY";
break;
case 3:
pdfName = "Chemistry.pdf";
subjectName = "CHEMISTRY";
break;
case 4:
pdfName = "EarthSpace.pdf";
subjectName = "EARTH AND SPACE";
break;
case 5:
pdfName = "Energy.pdf";
subjectName = "ENERGY";
break;
default:
break;
}
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("PDFs/" + pdfName));
document.open();
//main paragraph to start of main chapter
Paragraph subjectTitle = new Paragraph(subjectName+"\n", header);
//write chapter
Chapter subjectChapter = new Chapter(subjectTitle, 1);
subjectChapter.setNumberDepth(0);
String [] temp;
for(int i = 0; i < Subject.size(); i++){
temp = Subject.get(i);
Section questionSubject = subjectChapter.addSection(new Paragraph(subjectName, bigTitle));
if(names == 1) questionSubject.add(new Paragraph("Writer: " + temp[1], title)); //name of the question writer
if(temp[3].equals("Multiple Choice") && temp[4].equals("Short Answer")){
//Toss Up Multiple Choice
questionSubject.add(new Paragraph("Toss Up: Multiple Choice", title));
questionSubject.add(
new Paragraph(
"\t" + temp[6] + "\n\t\t" +
"W) " + temp[7] + "\n\t\t" +
"X) " + temp[8] + "\n\t\t" +
"Y) " + temp[9] + "\n\t\t" +
"Z) " + temp[10] + "\n", body));
questionSubject.add(new Paragraph("\tToss Up Answer: " + temp[11] + "\n-----------------------------------------------------------------------------------------------------------------------------------------------------------", title));
//Bonus Short Answer
questionSubject.add(new Paragraph("Bonus: Short Answer", title));
questionSubject.add(new Paragraph("\t" + temp[12] + "\n", body));
questionSubject.add(new Paragraph("\tBonus Answer: " + temp[13] + "\n=========================================================================================\n", title));
} else if(temp[3].equals("Multiple Choice") && temp[4].equals("Multiple Choice")){
//Toss Up Multiple Choice
questionSubject.add(new Paragraph("Toss Up: Multiple Choice", title));
questionSubject.add(
new Paragraph(
"\t" + temp[14] + "\n\t\t" +
"W) " + temp[15] + "\n\t\t" +
"X) " + temp[16] + "\n\t\t" +
"Y) " + temp[17] + "\n\t\t" +
"Z) " + temp[18] + "\n\n", body));
questionSubject.add(new Paragraph("\tToss Up Answer: " + temp[19] + "\n-----------------------------------------------------------------------------------------------------------------------------------------------------------", title));
//Bonus Multiple Choice
questionSubject.add(new Paragraph("Bonus: Multiple Choice", title));
questionSubject.add(
new Paragraph(
"\t" + temp[20] + "\n\t\t" +
"W) " + temp[21] + "\n\t\t" +
"X) " + temp[22] + "\n\t\t" +
"Y) " + temp[23] + "\n\t\t" +
"Z) " + temp[24] + "\n\n", body));
questionSubject.add(new Paragraph("\tBonus Answer: " + temp[25] + "\n=========================================================================================\n", title));
} else if(temp[3].equals("Short Answer") && temp[5].equals("Multiple Choice")){
//Toss Up Short Answer
questionSubject.add(new Paragraph("Toss Up: Short Answer", title));
questionSubject.add(new Paragraph("\t" + temp[26] + "\n", body));
questionSubject.add(new Paragraph("\tBonus Answer: " + temp[27] + "\n-----------------------------------------------------------------------------------------------------------------------------------------------------------", title));
//Bonus Multiple Choice
questionSubject.add(new Paragraph("Bonus: Multiple Choice", title));
questionSubject.add(
new Paragraph(
"\t" + temp[28] + "\n\t\t" +
"W) " + temp[29] + "\n\t\t" +
"X) " + temp[30] + "\n\t\t" +
"Y) " + temp[31] + "\n\t\t" +
"Z) " + temp[32] + "\n\n", body));
questionSubject.add(new Paragraph("\tBonus Answer: " + temp[33] + "\n=========================================================================================\n", title));
} else if(temp[3].equals("Short Answer") && temp[5].equals("Short Answer")){
//Toss Up Short Answer
questionSubject.add(new Paragraph("Toss Up: Short Answer", title));
questionSubject.add(new Paragraph("\t" + temp[34] + "\n", body));
questionSubject.add(new Paragraph("\tBonus Answer: " + temp[35] + "\n-----------------------------------------------------------------------------------------------------------------------------------------------------------", title));
//Bonus Short Answer
questionSubject.add(new Paragraph("Bonus: Short Answer", title));
questionSubject.add(new Paragraph("\t" + temp[36] + "\n", body));
questionSubject.add(new Paragraph("\tBonus Answer: " + temp[37] + "\n=========================================================================================\n", title));
} else {
System.out.println("UH OH SOMETHING WENT WRONG at: " + i + "; 3: " + temp[3] + " 4: " + temp[4] + " 5: " + temp[5] );
}
}
document.add(subjectChapter);
//Set attributes here
document.addAuthor("Shantanu Jha");
document.addCreationDate();
document.addCreator("https://sites.google.com/site/stuyvesantsciencebowl/");
document.addTitle("Physics");
document.addSubject("Physics Questions");
document.close();
writer.close();
}
} catch (Exception e)
{
e.printStackTrace();
}
}
}