Skip to content
Merged
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 @@ -8,6 +8,7 @@
package org.dspace.app.mediafilter;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -79,6 +80,13 @@ public InputStream getDestinationStream(Item currentItem, InputStream source, bo
} catch (InvalidPasswordException ex) {
log.error("PDF is encrypted. Cannot create thumbnail (item: {})", currentItem::getHandle);
return null;
} catch (IOException ex) {
// A malformed/non-standard PDF (bad %PDF- header, missing xref, truncated file, etc.)
// is a data-quality issue in the source bitstream, not a DSpace fault. Skip the
// thumbnail instead of failing the whole filter-media run.
log.warn("PDF could not be parsed by PDFBox. Cannot create thumbnail (item: {}): {}",
currentItem::getHandle, ex::getMessage);
return null;
}

// Generate thumbnail derivative and return as IO stream.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ public InputStream getDestinationStream(Item currentItem, InputStream source, bo
tika.setMaxStringLength(maxChars); // Tell Tika the maximum number of characters to extract
extractedText = tika.parseToString(source);
} catch (IOException e) {
System.err.format("Unable to extract text from bitstream in Item %s%n", currentItem.getID().toString());
e.printStackTrace(System.err);
log.error("Unable to extract text from bitstream in Item {}", currentItem.getID().toString(), e);
throw e;
// A malformed/non-standard source file (e.g. a PDF with a corrupt header, missing
// xref, or truncated content) is a data-quality issue in the bitstream, not a
// DSpace fault. Skip text extraction for it instead of failing the whole
// filter-media run.
log.warn("Unable to extract text from bitstream in Item {}: {}",
currentItem.getHandle(), e.getMessage());
return null;
} catch (OutOfMemoryError oe) {
System.err.format("OutOfMemoryError occurred when extracting text from bitstream in Item %s. " +
"You may wish to enable 'textextractor.use-temp-file'.%n", currentItem.getID().toString());
Expand Down
Loading