-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2. bump version to 0.1.3
- Loading branch information
Showing
9 changed files
with
61 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
AUTH | hwding | ||
DATE | Sep 05 2017 | ||
DATE | Sep 10 2017 | ||
DESC | text stamp remover for PDF files | ||
MAIL | [email protected] | ||
GITH | github.com/hwding | ||
|
@@ -37,7 +37,8 @@ public static void main(@NotNull String[] args) { | |
System.exit(0); | ||
} else { | ||
TaskRunner.init( | ||
commandLine.getOptionValues('k')); | ||
commandLine.getOptionValues('k'), | ||
commandLine.hasOption('s')); | ||
|
||
if (commandLine.hasOption('i') && (commandLine.hasOption('o') || commandLine.hasOption('d'))) { | ||
if (commandLine.hasOption('d')) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
AUTH | hwding | ||
DATE | Sep 05 2017 | ||
DATE | Sep 10 2017 | ||
DESC | text stamp remover for PDF files | ||
MAIL | [email protected] | ||
GITH | github.com/hwding | ||
|
@@ -27,7 +27,8 @@ | |
public class Processor { | ||
public static void process( | ||
@NotNull File file, | ||
@NotNull String[] strings) { | ||
@NotNull String[] strings, | ||
@NotNull boolean useStrict) { | ||
AtomicBoolean processAllOk = new AtomicBoolean(true); | ||
GeneralLogger.Processor.procInProgress(file.getName()); | ||
|
||
|
@@ -61,7 +62,7 @@ public static void process( | |
if (e instanceof COSString) { | ||
/* Ignore Any Exception During Parallel Processing */ | ||
try { | ||
if (TextStampRecognizer.recognize(strings, ((COSString) e).getBytes(), pdFonts)) | ||
if (TextStampRecognizer.recognize(strings, ((COSString) e).getBytes(), pdFonts, useStrict)) | ||
((COSString) e).setValue(new byte[0]); | ||
} catch (Exception ignored) { | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
AUTH | hwding | ||
DATE | Sep 05 2017 | ||
DATE | Sep 10 2017 | ||
DESC | text stamp remover for PDF files | ||
MAIL | [email protected] | ||
GITH | github.com/hwding | ||
|
@@ -18,15 +18,16 @@ class TextStampRecognizer { | |
private static boolean recognizeWithFont( | ||
@NotNull String[] keywords, | ||
@NotNull byte[] inputText, | ||
@NotNull Set<PDFont> pdFonts) { | ||
String bs = generateByteString(inputText); | ||
@NotNull Set<PDFont> pdFonts, | ||
@NotNull boolean useStrict) { | ||
String encodedInput = generateByteString(inputText); | ||
for (PDFont f : pdFonts) { | ||
if (f == null) continue; | ||
for (String k : keywords) { | ||
try { | ||
byte[] encodedKeywords = f.encode(k); | ||
if (bs.contains(generateByteString(encodedKeywords))) | ||
return true; | ||
byte[] encodedKeywordBytes = f.encode(k); | ||
final String encodedKeyword = generateByteString(encodedKeywordBytes); | ||
if (checkDuplicate(encodedInput, encodedKeyword, useStrict)) return true; | ||
} catch (IOException | IllegalArgumentException ignored) { | ||
} | ||
} | ||
|
@@ -36,26 +37,38 @@ private static boolean recognizeWithFont( | |
|
||
private static boolean recognizePlain( | ||
@NotNull String[] keywords, | ||
@NotNull byte[] inputText | ||
@NotNull byte[] inputText, | ||
@NotNull boolean useStrict | ||
) { | ||
for (String k : keywords) { | ||
if (new String(inputText).contains(k)) return true; | ||
for (String k : keywords) | ||
if (checkDuplicate(new String(inputText), k, useStrict)) return true; | ||
return false; | ||
} | ||
|
||
private static boolean checkDuplicate( | ||
@NotNull String input, | ||
@NotNull String keyword, | ||
@NotNull boolean useStrict) { | ||
if (useStrict) { | ||
if (input.equals(keyword)) return true; | ||
} else { | ||
if (input.contains(keyword)) return true; | ||
} | ||
return false; | ||
} | ||
|
||
static boolean recognize(@NotNull String[] keywords, | ||
@NotNull byte[] inputText, | ||
@NotNull Set<PDFont> pdFonts) { | ||
return recognizePlain(keywords, inputText) || | ||
recognizeWithFont(keywords, inputText, pdFonts); | ||
@NotNull Set<PDFont> pdFonts, | ||
@NotNull boolean useStrict) { | ||
return recognizePlain(keywords, inputText, useStrict) || | ||
recognizeWithFont(keywords, inputText, pdFonts, useStrict); | ||
} | ||
|
||
private static String generateByteString(@NotNull byte[] bytes) { | ||
StringBuilder stringBuilder = new StringBuilder(); | ||
for (byte b : bytes) { | ||
for (byte b : bytes) | ||
stringBuilder.append(Byte.toString(b)); | ||
} | ||
return stringBuilder.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
AUTH | hwding | ||
DATE | Sep 05 2017 | ||
DATE | Sep 10 2017 | ||
DESC | text stamp remover for PDF files | ||
MAIL | [email protected] | ||
GITH | github.com/hwding | ||
|
@@ -12,13 +12,16 @@ | |
public class GeneralLogger { | ||
public static class Help { | ||
private static final String usage = | ||
"\nPDF-UnStamper ver. 0.1.2 by hwding@GitHub\n" + | ||
"\nPDF-UnStamper ver. 0.1.3 by hwding@GitHub\n" + | ||
"\nUsage:" + | ||
"\n [OPTION] -i [INPUT PDF] -k [KEYWORDS...] (-o [OUTPUT PDF])" + | ||
"\n [OPTION] -I [INPUT DIR] -k [KEYWORDS...] (-O [OUTPUT DIR])\n" + | ||
"\nOptions:" + | ||
"\n -d, --directly directly modify the input file(s), which makes option o/O unnecessary" + | ||
"\n -r, --recursive process files in the given dir recursively\n"; | ||
"\n -d, --directly directly modify the input file(s), option o/O is\n" + | ||
" unnecessary when this option is on" + | ||
"\n -r, --recursive process files in the given dir recursively" + | ||
"\n -s, --strict use strict mode, a text area is considered as water mark\n" + | ||
" only if its content strictly equals one of the keywords\n"; | ||
|
||
public static void print() { | ||
System.out.println(usage); | ||
|
@@ -61,7 +64,7 @@ public static void procInProgress(@NotNull String fn) { | |
} | ||
|
||
public static void procFinished() { | ||
System.out.println(" GOOD"); | ||
System.out.println(" done"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
AUTH | hwding | ||
DATE | Aug 25 2017 | ||
DATE | Sep 10 2017 | ||
DESC | text stamp remover for PDF files | ||
MAIL | [email protected] | ||
GITH | github.com/hwding | ||
|
@@ -18,6 +18,7 @@ public class OptionManager { | |
private final static Option optionK = new Option("k", true, null); | ||
private final static Option optionD = new Option("d", "directly", false, null); | ||
private final static Option optionR = new Option("r", "recursive", false, null); | ||
private final static Option optionS = new Option("s", "strict", false, null); | ||
|
||
public static Options buildOptions() { | ||
Options options = new Options(); | ||
|
@@ -34,6 +35,7 @@ public static Options buildOptions() { | |
options.addOption(optionD); | ||
options.addOption(optionR); | ||
options.addOption(optionK); | ||
options.addOption(optionS); | ||
return options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
AUTH | hwding | ||
DATE | Sep 05 2017 | ||
DATE | Sep 10 2017 | ||
DESC | text stamp remover for PDF files | ||
MAIL | [email protected] | ||
GITH | github.com/hwding | ||
|
@@ -19,9 +19,13 @@ | |
|
||
public class TaskRunner { | ||
private static String[] keywords; | ||
private static boolean useStrict; | ||
|
||
public static void init(@NotNull String[] keywords) { | ||
public static void init( | ||
@NotNull String[] keywords, | ||
@NotNull boolean useStrict) { | ||
TaskRunner.keywords = keywords; | ||
TaskRunner.useStrict = useStrict; | ||
} | ||
|
||
public static void procSingleFile( | ||
|
@@ -42,7 +46,7 @@ public static void procSingleFile( | |
} | ||
|
||
private static void submitToProcessor(@NotNull File file) { | ||
Processor.process(file, keywords); | ||
Processor.process(file, keywords, useStrict); | ||
} | ||
|
||
public static void procSingleFileDirectly(@NotNull String ifn) { | ||
|