Skip to content

Commit 471d56f

Browse files
committed
Merge branch 'master' of https://github.com/cityssm/pdfFlattener
2 parents 525d553 + 36d5a3f commit 471d56f

File tree

2 files changed

+16
-30
lines changed

2 files changed

+16
-30
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
1+
.idea/
22
*.pdf

src/ca/saultstemarie/pdfflattener/FlattenPDF.java

+15-29
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ public class FlattenPDF {
2727
/**
2828
* Whether or not debug output is printed to the console.
2929
*/
30-
public static boolean SHOW_DEBUG = true;
30+
public static final boolean SHOW_DEBUG = true;
3131

3232
/**
3333
* The suggested prefix to add to output files.
3434
*/
35-
public static String DESTINATION_FILENAME_PREFIX = "flat--";
35+
public static final String DESTINATION_FILENAME_PREFIX = "flat--";
3636

3737
/**
3838
* The DPI that should be used when generating images.
3939
* Higher DPI increases the memory requirements and output file sizes, but also produces sharper images.
4040
*/
41-
public static int IMAGE_DPI = 200;
41+
public static final int IMAGE_DPI = 200;
4242

4343

4444
public static void main(String[] args) {
@@ -66,25 +66,16 @@ public static void main(String[] args) {
6666
* Get the source file
6767
*/
6868

69-
File sourceFile = null;
70-
71-
boolean sourceFileFromArgument = false;
72-
69+
File sourceFile;
70+
7371
if (args.length >= 1) {
7472
sourceFile = new File(args[0]);
75-
7673
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);
7976
System.exit(1);
8077
}
81-
else {
82-
sourceFileFromArgument = true;
83-
}
84-
}
85-
86-
if (!sourceFileFromArgument) {
87-
78+
} else {
8879
fileChooser.setDialogTitle("Select the Source PDF File to Flatten");
8980
fileChooser.setApproveButtonText("Set Source PDF");
9081

@@ -102,24 +93,19 @@ public static void main(String[] args) {
10293
* Get the destination file
10394
*/
10495

105-
File destinationFile = null;
106-
boolean destinationFileFromArgument = false;
96+
File destinationFile;
10797

10898
if (args.length >= 2) {
10999
destinationFile = new File(args[1]);
110-
111-
if (!sourceFile.getName().toLowerCase().endsWith(".pdf")) {
100+
101+
if (!destinationFile.getName().toLowerCase().endsWith(".pdf")) {
112102
JOptionPane.showMessageDialog(null, "Invalid destination file.\n" +
113-
args[0], "Error", JOptionPane.ERROR_MESSAGE);
103+
args[1], "Error", JOptionPane.ERROR_MESSAGE);
114104
System.exit(1);
115105
}
116-
else {
117-
destinationFileFromArgument = true;
118-
}
119106
}
120-
121-
if (!destinationFileFromArgument) {
122-
107+
else {
108+
123109
destinationFile = new File(sourceFile.getAbsolutePath() + File.separator + DESTINATION_FILENAME_PREFIX + sourceFile.getName());
124110

125111
fileChooser.setDialogTitle("Select the Destination PDF File");
@@ -288,7 +274,7 @@ public void put (COSObject indirect, PDXObject xobject) {
288274

289275
return 0;
290276
}
291-
277+
292278
private static void log(String message) {
293279
if (SHOW_DEBUG) {
294280
System.out.println(new Date().toString() + " - " + message);

0 commit comments

Comments
 (0)