Compare commits
4 Commits
38cf112230
...
72bc06e695
Author | SHA1 | Date |
---|---|---|
CocoMaster-AI | 72bc06e695 | |
CocoMaster-AI | 2cc16f3cc9 | |
CocoMaster-AI | 0c848acc0c | |
Anthony Stirling | 2fff3083ae |
|
@ -19,6 +19,16 @@ public class TextFinder extends PDFTextStripper {
|
||||||
private final boolean wholeWordSearch;
|
private final boolean wholeWordSearch;
|
||||||
private final List<PDFText> textOccurrences = new ArrayList<>();
|
private final List<PDFText> textOccurrences = new ArrayList<>();
|
||||||
|
|
||||||
|
private class MatchInfo {
|
||||||
|
int startIndex;
|
||||||
|
int matchLength;
|
||||||
|
|
||||||
|
MatchInfo(int startIndex, int matchLength) {
|
||||||
|
this.startIndex = startIndex;
|
||||||
|
this.matchLength = matchLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public TextFinder(String searchText, boolean useRegex, boolean wholeWordSearch)
|
public TextFinder(String searchText, boolean useRegex, boolean wholeWordSearch)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
this.searchText = searchText.toLowerCase();
|
this.searchText = searchText.toLowerCase();
|
||||||
|
@ -27,36 +37,37 @@ public class TextFinder extends PDFTextStripper {
|
||||||
setSortByPosition(true);
|
setSortByPosition(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Integer> findOccurrencesInText(String searchText, String content) {
|
private List<MatchInfo> findOccurrencesInText(String searchText, String content) {
|
||||||
List<Integer> indexes = new ArrayList<>();
|
List<MatchInfo> matches = new ArrayList<>();
|
||||||
|
|
||||||
Pattern pattern;
|
Pattern pattern;
|
||||||
|
|
||||||
if (useRegex) {
|
if (useRegex) {
|
||||||
// Use regex-based search
|
// Use regex-based search
|
||||||
pattern =
|
pattern =
|
||||||
wholeWordSearch
|
wholeWordSearch
|
||||||
? Pattern.compile("(\\b|_|\\.)" + searchText + "(\\b|_|\\.)")
|
? Pattern.compile("\\b" + searchText + "\\b")
|
||||||
: Pattern.compile(searchText);
|
: Pattern.compile(searchText);
|
||||||
} else {
|
} else {
|
||||||
// Use normal text search
|
// Use normal text search
|
||||||
pattern =
|
pattern =
|
||||||
wholeWordSearch
|
wholeWordSearch
|
||||||
? Pattern.compile(
|
? Pattern.compile("\\b" + Pattern.quote(searchText) + "\\b")
|
||||||
"(\\b|_|\\.)" + Pattern.quote(searchText) + "(\\b|_|\\.)")
|
|
||||||
: Pattern.compile(Pattern.quote(searchText));
|
: Pattern.compile(Pattern.quote(searchText));
|
||||||
}
|
}
|
||||||
|
|
||||||
Matcher matcher = pattern.matcher(content);
|
Matcher matcher = pattern.matcher(content);
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
indexes.add(matcher.start());
|
matches.add(new MatchInfo(matcher.start(), matcher.end() - matcher.start()));
|
||||||
}
|
}
|
||||||
return indexes;
|
return matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void writeString(String text, List<TextPosition> textPositions) {
|
protected void writeString(String text, List<TextPosition> textPositions) {
|
||||||
for (Integer index : findOccurrencesInText(searchText, text.toLowerCase())) {
|
for (MatchInfo match : findOccurrencesInText(searchText, text.toLowerCase())) {
|
||||||
if (index + searchText.length() <= textPositions.size()) {
|
int index = match.startIndex;
|
||||||
|
if (index + match.matchLength <= textPositions.size()) {
|
||||||
// Initial values based on the first character
|
// Initial values based on the first character
|
||||||
TextPosition first = textPositions.get(index);
|
TextPosition first = textPositions.get(index);
|
||||||
float minX = first.getX();
|
float minX = first.getX();
|
||||||
|
@ -65,7 +76,7 @@ public class TextFinder extends PDFTextStripper {
|
||||||
float maxY = first.getY() + first.getHeight();
|
float maxY = first.getY() + first.getHeight();
|
||||||
|
|
||||||
// Loop over the rest of the characters and adjust bounding box values
|
// Loop over the rest of the characters and adjust bounding box values
|
||||||
for (int i = index; i < index + searchText.length(); i++) {
|
for (int i = index; i < index + match.matchLength; i++) {
|
||||||
TextPosition position = textPositions.get(i);
|
TextPosition position = textPositions.get(i);
|
||||||
minX = Math.min(minX, position.getX());
|
minX = Math.min(minX, position.getX());
|
||||||
minY = Math.min(minY, position.getY());
|
minY = Math.min(minY, position.getY());
|
||||||
|
|
|
@ -11,10 +11,10 @@ imgPrompt=画像を選択
|
||||||
genericSubmit=送信
|
genericSubmit=送信
|
||||||
processTimeWarning=警告:この処理はファイルサイズによって1分程度かかることがあります
|
processTimeWarning=警告:この処理はファイルサイズによって1分程度かかることがあります
|
||||||
pageOrderPrompt=ページ順序 (ページ番号をカンマ区切り又は2n+1のような関数で入力):
|
pageOrderPrompt=ページ順序 (ページ番号をカンマ区切り又は2n+1のような関数で入力):
|
||||||
pageSelectionPrompt=Custom Page Selection (Enter a comma-separated list of page numbers 1,5,6 or Functions like 2n+1) :
|
pageSelectionPrompt=カスタムページ選択(ページ番号1、5、6または2n + 1などの関数のコンマ区切りリストを入力します):
|
||||||
goToPage=移動
|
goToPage=移動
|
||||||
true=True
|
true=真
|
||||||
false=False
|
false=偽
|
||||||
unknown=不明
|
unknown=不明
|
||||||
save=保存
|
save=保存
|
||||||
saveToBrowser=ブラウザへ保存
|
saveToBrowser=ブラウザへ保存
|
||||||
|
@ -63,7 +63,7 @@ deleteUsernameExistsMessage=そのユーザー名は存在しないため削除
|
||||||
# Pipeline #
|
# Pipeline #
|
||||||
###############
|
###############
|
||||||
pipeline.header=パイプラインメニュー (Alpha)
|
pipeline.header=パイプラインメニュー (Alpha)
|
||||||
pipeline.uploadButton=Upload Custom
|
pipeline.uploadButton=カスタムのアップロード
|
||||||
pipeline.configureButton=設定
|
pipeline.configureButton=設定
|
||||||
pipeline.defaultOption=カスタム
|
pipeline.defaultOption=カスタム
|
||||||
pipeline.submitButton=送信
|
pipeline.submitButton=送信
|
||||||
|
@ -75,7 +75,7 @@ pipelineOptions.header=パイプライン設定
|
||||||
pipelineOptions.pipelineNameLabel=パイプライン名
|
pipelineOptions.pipelineNameLabel=パイプライン名
|
||||||
pipelineOptions.saveSettings=動作設定の保存
|
pipelineOptions.saveSettings=動作設定の保存
|
||||||
pipelineOptions.pipelineNamePrompt=ここにパイプライン名を入力
|
pipelineOptions.pipelineNamePrompt=ここにパイプライン名を入力
|
||||||
pipelineOptions.selectOperation=Select Operation
|
pipelineOptions.selectOperation=動作の選択
|
||||||
pipelineOptions.addOperationButton=動作の追加
|
pipelineOptions.addOperationButton=動作の追加
|
||||||
pipelineOptions.pipelineHeader=パイプライン:
|
pipelineOptions.pipelineHeader=パイプライン:
|
||||||
pipelineOptions.saveButton=ダウンロード
|
pipelineOptions.saveButton=ダウンロード
|
||||||
|
@ -166,7 +166,7 @@ home.desc=PDFのあらゆるニーズに対応するローカルホスティン
|
||||||
home.searchBar=機能検索...
|
home.searchBar=機能検索...
|
||||||
|
|
||||||
|
|
||||||
home.viewPdf.title=View PDF
|
home.viewPdf.title=PDFを表示
|
||||||
home.viewPdf.desc=表示、注釈、テキストや画像の追加
|
home.viewPdf.desc=表示、注釈、テキストや画像の追加
|
||||||
viewPdf.tags=view,read,annotate,text,image
|
viewPdf.tags=view,read,annotate,text,image
|
||||||
|
|
||||||
|
@ -540,7 +540,7 @@ addPageNumbers.selectText.5=番号をつけるページ
|
||||||
addPageNumbers.selectText.6=カスタムテキスト
|
addPageNumbers.selectText.6=カスタムテキスト
|
||||||
addPageNumbers.customTextDesc=カスタムテキスト
|
addPageNumbers.customTextDesc=カスタムテキスト
|
||||||
addPageNumbers.numberPagesDesc=番号をつけるページ、デフォルトは'all'、 1-5 や 2,5,9 など
|
addPageNumbers.numberPagesDesc=番号をつけるページ、デフォルトは'all'、 1-5 や 2,5,9 など
|
||||||
addPageNumbers.customNumberDesc=デフォルトは{n}、'{n} / {total} ページ'、'テキスト-{n}'、'{filename}-{n}など
|
addPageNumbers.customNumberDesc=デフォルトは{n}、'{n} / {total} ページ'、'テキスト-{n}'、'{filename}-{n}など'
|
||||||
addPageNumbers.submit=ページ番号の追加
|
addPageNumbers.submit=ページ番号の追加
|
||||||
|
|
||||||
|
|
||||||
|
@ -763,8 +763,8 @@ multiTool.title=PDFマルチツール
|
||||||
multiTool.header=PDFマルチツール
|
multiTool.header=PDFマルチツール
|
||||||
|
|
||||||
#view pdf
|
#view pdf
|
||||||
viewPdf.title=View PDF
|
viewPdf.title=PDFを表示
|
||||||
viewPdf.header=View PDF
|
viewPdf.header=PDFを表示
|
||||||
|
|
||||||
#pageRemover
|
#pageRemover
|
||||||
pageRemover.title=ページ削除
|
pageRemover.title=ページ削除
|
||||||
|
|
Loading…
Reference in New Issue