Skip to content
Closed
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 @@ -23,6 +23,7 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -319,11 +320,15 @@ protected StyledDocument doInBackground() throws IOException
{
return getXMLDocument(inputStream);
}
StyledDocument document = getContentStreamDocument(inputStream);
// read the data only once, so that it is still available for the
// plain text fallback if parsing as a content stream fails
byte[] data = inputStream.readAllBytes();
StyledDocument document = getContentStreamDocument(data);
if (document != null)
{
return document;
}
return getDocument(new ByteArrayInputStream(data), encoding);
}
return getDocument(inputStream, encoding);
}
Expand Down Expand Up @@ -403,14 +408,14 @@ private StyledDocument getXMLDocument(InputStream inputStream)
return docu;
}

private StyledDocument getContentStreamDocument(InputStream inputStream)
private StyledDocument getContentStreamDocument(byte[] data)
{
StyledDocument docu = new DefaultStyledDocument();

PDFStreamParser parser;
try
{
parser = new PDFStreamParser(inputStream.readAllBytes());
parser = new PDFStreamParser(data);
parser.parse().forEach(obj -> writeToken(obj, docu));
}
catch (IOException e)
Expand Down