I have pdfs with a single, full-page CCITT fax encoded image on each page. I have code cut using iText that will successfully get me to the PRStream for the image data for a page, however the PRStream returns null when I call stream.getBytes(). If this would actually return the byte array, I could use the TIFFFaxDecoder in iText to decode the image and dump it to a JAI WritableRaster. Why is my PRStream not returning the byte array?
My code for getting the PRStream for a specific page follows:
  private PdfDictionary dict;
  private PRStream stream;
  private ArrayList list;
  private int length = 0;
  private int width = 0;
  private int height = 0;
  private int bpc = 0;
  private int k = 0;
  private int columns = 0;
  private int offset = 0;
  private String filter;
  private String colorSpace;

     //get the dictionary representing the page
     dict = reader.getPageN(next);
     //the page dictionary contains a resources dictionary
     dict = (PdfDictionary)dict.get(PdfName.RESOURCES);
     //the resources dictionary contains an xobject dictionary
     dict = (PdfDictionary)dict.get(PdfName.XOBJECT);
     //the xobj dictionary contains an indirect reference to a PRStream
stream = (PRStream)PdfReader.getPdfObject(dict.get(new PdfName("Xf" + next)));
     //the PRStream's dictionary contains a resources dictionary
     dict = (PdfDictionary)stream.get(PdfName.RESOURCES);
     //the resources dictionary has an xobject dictionary
     dict = (PdfDictionary)dict.get(PdfName.XOBJECT);
     //the xobject dictionary contains and indirect reference to a PRStream
stream = (PRStream)PdfReader.getPdfObject(dict.get(new PdfName("Im" + next)));
     //get length
     length = ((PdfNumber)stream.get(PdfName.LENGTH)).intValue();
     //get width
     width = ((PdfNumber)stream.get(PdfName.WIDTH)).intValue();
     //get height
     height = ((PdfNumber)stream.get(PdfName.HEIGHT)).intValue();
     //get bits per component
     bpc = ((PdfNumber)stream.get(PdfName.BITSPERCOMPONENT)).intValue();

     //the PRStream's dictionary has a filter array
     list = ((PdfArray)stream.get(PdfName.FILTER)).getArrayList();
     //the filter array contains the name of the filter to use
     filter = ((PdfName)list.get(0)).toString();

     //the PRStream's dictionary has a colorspace array
     list = ((PdfArray)stream.get(PdfName.COLORSPACE)).getArrayList();
     //the colorspace array contains the name of the colorspace
     colorSpace = ((PdfName)list.get(0)).toString();

     //the PRStream's dictionary has a decode parameters array
     list = ((PdfArray)stream.get(PdfName.DECODEPARMS)).getArrayList();
     //the decode parameters array contains a dictionary
     dict = (PdfDictionary)list.get(0);
     //the dictionary contains the k value for CCITT decoding
     k = ((PdfNumber)dict.get(PdfName.K)).intValue();
     //the dictionary contains the columns for CCITT decoding
     columns = ((PdfNumber)dict.get(PdfName.COLUMNS)).intValue();
     //get the byte offset into the pdf data where the image data starts
     offset = stream.getOffset();

     byte[] data = stream.getBytes();



-------------------------------------------------------
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

Reply via email to