Possible solution:
Adding a getUnfilteredStreamBytes() method to PdfReader would allow
users to access a stream's bytes even if the stream's filter is not yet
supported by iText. This would allow a programmer to filter the stream
himself. The following is the method I added to my copy of iText to
implement the functionality.
public static byte[] getUnfilteredStreamBytes(PRStream stream,
RandomAccessFileOrArray
file)
throws IOException
{
PdfReader reader = stream.getReader();
byte[] b;
if (stream.getOffset() < 0)
{
b = stream.getBytes();
}
else
{
b = new byte[stream.getLength()];
file.seek(stream.getOffset());
file.readFully(b);
PdfEncryption decrypt = reader.getDecrypt();
if (decrypt != null)
{
decrypt.setHashKey(stream.getObjNum(), stream.getObjGen());
decrypt.prepareKey();
decrypt.encryptRC4(b);
}
}
return b;
}
John Pruitt wrote:
I am trying to get a CCITTFax encoded stream out of a pdf file.
PdfReader.getStreamBytes(PRStream stream) reads a byte stream from the
pdf file, decrypts the stream if neccessary, attempts to apply any
filters to the stream, and then returns the byte array. This would be
perfect for what I need to do, except that the method does not
recognize the /CCITTFaxDecode filter. The method throws an
IOException: "The filter /CCITTFaxDecode is not supported." While I
understand why this method was coded in this way, it makes it
impossible for me to actually get to the byte array for my CCITT data.
If the method were to simply return the unfiltered byte array in the
case that it found a filter it did not recognize, then the user would
be able to apply the appropriate filter manually. I have code to
decode the CCITT data, but this method will not let me get to the data.
The following code does actually get the byte stream from the file,
however my pdfs are encrypted and thus the byte array is encrypted. I
am unable to decrypt the stream manually because the
PdfReader.getDecrypt() is a private method.
RandomAccessFileOrArray rf = reader.getSafeFile();
rf.reOpen();
rf.seek(offset);
rf.readFully(encoded_data);
rf.close();
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log
files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions