Skip to content

fix for TIKA-3134 contributed by tothd #327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ protected void endPage(PDPage page) throws IOException {
doOCROnCurrentPage();
} else if (config.getOcrStrategy().equals(PDFParserConfig.OCR_STRATEGY.AUTO)) {
//TODO add more sophistication
if (totalCharsPerPage < 10 || unmappedUnicodeCharsPerPage > 10) {
if (totalCharsPerPage < config.getTotalCharsPerPage() || unmappedUnicodeCharsPerPage > config.getUnmappedUnicodeCharsPerPage()) {
doOCROnCurrentPage();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ private static OCR_STRATEGY parse(String s) {

private boolean detectAngles = false;

private int totalCharsPerPage = 10;

private int unmappedUnicodeCharsPerPage = 10;

public PDFParserConfig() {
init(this.getClass().getResourceAsStream("PDFParser.properties"));
}
Expand Down Expand Up @@ -263,6 +267,14 @@ private void init(InputStream is) {

maxMainMemoryBytes = getLongProp(props.getProperty("maxMainMemoryBytes"), -1);
detectAngles = getBooleanProp(props.getProperty("detectAngles"), false);

setTotalCharsPerPage(
getIntProp(props.getProperty("totalCharsPerPage"),
getTotalCharsPerPage()));

setUnmappedUnicodeCharsPerPage(
getIntProp(props.getProperty("unmappedUnicodeCharsPerPage"),
getUnmappedUnicodeCharsPerPage()));
}

/**
Expand Down Expand Up @@ -838,6 +850,22 @@ public boolean getDetectAngles() {
return detectAngles;
}

public void setTotalCharsPerPage(int totalCharsPerPage) {
this.totalCharsPerPage = totalCharsPerPage;
}

public int getTotalCharsPerPage() {
return totalCharsPerPage;
}

public void setUnmappedUnicodeCharsPerPage(int unmappedUnicodeCharsPerPage) {
this.unmappedUnicodeCharsPerPage = unmappedUnicodeCharsPerPage;
}

public int getUnmappedUnicodeCharsPerPage() {
return unmappedUnicodeCharsPerPage;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -864,6 +892,8 @@ public boolean equals(Object o) {
if (!getOcrImageFormatName().equals(config.getOcrImageFormatName())) return false;
if (getExtractActions() != config.getExtractActions()) return false;
if (!getAccessChecker().equals(config.getAccessChecker())) return false;
if (getTotalCharsPerPage() != config.getTotalCharsPerPage()) return false;
if (getUnmappedUnicodeCharsPerPage() != config.getUnmappedUnicodeCharsPerPage()) return false;
return getMaxMainMemoryBytes() == config.getMaxMainMemoryBytes();
}

Expand All @@ -889,6 +919,8 @@ public int hashCode() {
result = 31 * result + (getCatchIntermediateIOExceptions() ? 1 : 0);
result = 31 * result + (getExtractActions() ? 1 : 0);
result = 31 * result + Long.valueOf(getMaxMainMemoryBytes()).hashCode();
result = 31 * result + getTotalCharsPerPage();
result = 31 * result + getUnmappedUnicodeCharsPerPage();
return result;
}

Expand All @@ -915,6 +947,8 @@ public String toString() {
", extractActions=" + extractActions +
", catchIntermediateIOExceptions=" + catchIntermediateIOExceptions +
", maxMainMemoryBytes=" + maxMainMemoryBytes +
", totalCharsPerPage=" + totalCharsPerPage +
", unmappedUnicodeCharsPerPage=" + unmappedUnicodeCharsPerPage +
'}';
}
}