@@ -27,18 +27,18 @@ public class FlattenPDF {
27
27
/**
28
28
* Whether or not debug output is printed to the console.
29
29
*/
30
- public static boolean SHOW_DEBUG = true ;
30
+ public static final boolean SHOW_DEBUG = true ;
31
31
32
32
/**
33
33
* The suggested prefix to add to output files.
34
34
*/
35
- public static String DESTINATION_FILENAME_PREFIX = "flat--" ;
35
+ public static final String DESTINATION_FILENAME_PREFIX = "flat--" ;
36
36
37
37
/**
38
38
* The DPI that should be used when generating images.
39
39
* Higher DPI increases the memory requirements and output file sizes, but also produces sharper images.
40
40
*/
41
- public static int IMAGE_DPI = 200 ;
41
+ public static final int IMAGE_DPI = 200 ;
42
42
43
43
44
44
public static void main (String [] args ) {
@@ -66,25 +66,16 @@ public static void main(String[] args) {
66
66
* Get the source file
67
67
*/
68
68
69
- File sourceFile = null ;
70
-
71
- boolean sourceFileFromArgument = false ;
72
-
69
+ File sourceFile ;
70
+
73
71
if (args .length >= 1 ) {
74
72
sourceFile = new File (args [0 ]);
75
-
76
73
if (!sourceFile .exists () || !sourceFile .isFile () || !sourceFile .canRead () || !sourceFile .getName ().toLowerCase ().endsWith (".pdf" )) {
77
- JOptionPane .showMessageDialog (null , "Invalid source file.\n " +
78
- args [ 0 ], "Error" , JOptionPane .ERROR_MESSAGE );
74
+ JOptionPane .showMessageDialog (null , "Invalid source file.\n " + args [ 0 ],
75
+ "Error" , JOptionPane .ERROR_MESSAGE );
79
76
System .exit (1 );
80
77
}
81
- else {
82
- sourceFileFromArgument = true ;
83
- }
84
- }
85
-
86
- if (!sourceFileFromArgument ) {
87
-
78
+ } else {
88
79
fileChooser .setDialogTitle ("Select the Source PDF File to Flatten" );
89
80
fileChooser .setApproveButtonText ("Set Source PDF" );
90
81
@@ -102,24 +93,19 @@ public static void main(String[] args) {
102
93
* Get the destination file
103
94
*/
104
95
105
- File destinationFile = null ;
106
- boolean destinationFileFromArgument = false ;
96
+ File destinationFile ;
107
97
108
98
if (args .length >= 2 ) {
109
99
destinationFile = new File (args [1 ]);
110
-
111
- if (!sourceFile .getName ().toLowerCase ().endsWith (".pdf" )) {
100
+
101
+ if (!destinationFile .getName ().toLowerCase ().endsWith (".pdf" )) {
112
102
JOptionPane .showMessageDialog (null , "Invalid destination file.\n " +
113
- args [0 ], "Error" , JOptionPane .ERROR_MESSAGE );
103
+ args [1 ], "Error" , JOptionPane .ERROR_MESSAGE );
114
104
System .exit (1 );
115
105
}
116
- else {
117
- destinationFileFromArgument = true ;
118
- }
119
106
}
120
-
121
- if (!destinationFileFromArgument ) {
122
-
107
+ else {
108
+
123
109
destinationFile = new File (sourceFile .getAbsolutePath () + File .separator + DESTINATION_FILENAME_PREFIX + sourceFile .getName ());
124
110
125
111
fileChooser .setDialogTitle ("Select the Destination PDF File" );
@@ -288,7 +274,7 @@ public void put (COSObject indirect, PDXObject xobject) {
288
274
289
275
return 0 ;
290
276
}
291
-
277
+
292
278
private static void log (String message ) {
293
279
if (SHOW_DEBUG ) {
294
280
System .out .println (new Date ().toString () + " - " + message );
0 commit comments