-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPDF2TXT Java GUI
More file actions
81 lines (68 loc) · 2.56 KB
/
PDF2TXT Java GUI
File metadata and controls
81 lines (68 loc) · 2.56 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
import javax.swing.*;
import java.io.IOException;
import java.nio.file.*;
public class PDf2TXT_GUI extends JFrame{
//define instance variable
// this actually does the GUI program itself
public static void main(String[] args){
// check if pdf2txt is already installed, install if it isn't
String userName = System.getProperty("user.name");
String filePath = "/home/" + userName + "/Packages/pdf2txt_venv_gui";
Path path = Paths.get(filePath);
if (!Files.exists(path)){
try {
Process p;
p = Runtime.getRuntime().exec("bash ./GUI_build_wrapper");
p.waitFor();
p.destroy();
} catch (IOException | InterruptedException ex) {
ex.printStackTrace();
}
}
// create the window itself
JFrame window = new JFrame();
window.setSize(500, 350);
window.setLayout(null);
window.setLocationRelativeTo(null);
window.setName(".pdf to .txt converter graphical version 1.0.0");
//create the label at the top to introduce the program
JLabel intro = new JLabel("This program runs PDF2TXT graphically.");
intro.setBounds(125, 25, 450, 20);
window.add(intro);
//create the entry fields for the input and output file paths
//infile
JTextField infile = new JTextField("input file path");
infile.setBounds(50, 75, 400, 20);
window.add(infile);
//outfile
JTextField outfile = new JTextField("output file path");
outfile.setBounds(50, 125, 400, 20);
window.add(outfile);
//create a checkbox for whole file or partial file conversion
JCheckBox wholeFile = new JCheckBox("Convert whole directory?");
wholeFile.setBounds(152, 175, 300, 20);
window.add(wholeFile);
// the run button to execute the program
JButton run = new JButton("Run PDF2TXT");
run.setBounds(160, 225, 150, 20);
window.add(run);
// this will happen when the run button is pressed.
run.addActionListener(e -> {
String inPath = infile.getText();
String outPath = outfile.getText();
String convertDirectory = "-f";
if (wholeFile.isSelected()){ convertDirectory = "-d";}
String runScript = ("bash ./wrapper " + convertDirectory + " " + inPath + " -o " + outPath);
System.out.println(runScript);
try {
Process p = Runtime.getRuntime().exec(runScript);
p.waitFor();
p.destroy();
} catch (IOException | InterruptedException ex) {
ex.printStackTrace();
}
});
// make the completed window visible
window.setVisible(true);
}
}