/// <summary> /// Gets a byte array that can be used as a /JBIG2Globals, /// or null if not applicable to the given jbig2. /// </summary> /// <param name="ra">an random access file or array</param> /// <returns>a byte array</returns> public static byte[] GetGlobalSegment(RandomAccessFileOrArray ra) { try { Jbig2SegmentReader sr = new Jbig2SegmentReader(ra); sr.Read(); return(sr.GetGlobal(true)); } catch (Exception) { return(null); } }
/// <summary>Gets the number of pages in a JBIG2 image.</summary> /// <param name="raf"> /// a /// <c>RandomAccessFileOrArray</c> /// containing a JBIG2 image /// </param> /// <returns>the number of pages</returns> public static int GetNumberOfPages(RandomAccessFileOrArray raf) { try { Jbig2SegmentReader sr = new Jbig2SegmentReader(raf); sr.Read(); return(sr.NumberOfPages()); } catch (Exception e) { throw new iText.IO.IOException(iText.IO.IOException.Jbig2ImageException, e); } }
public static void ProcessImage(ImageData jbig2) { if (jbig2.GetOriginalType() != ImageType.JBIG2) { throw new ArgumentException("JBIG2 image expected"); } Jbig2ImageData image = (Jbig2ImageData)jbig2; try { IRandomAccessSource ras; if (image.GetData() == null) { image.LoadData(); } ras = new RandomAccessSourceFactory().CreateSource(image.GetData()); RandomAccessFileOrArray raf = new RandomAccessFileOrArray(ras); Jbig2SegmentReader sr = new Jbig2SegmentReader(raf); sr.Read(); Jbig2SegmentReader.Jbig2Page p = sr.GetPage(image.GetPage()); raf.Close(); image.SetHeight(p.pageBitmapHeight); image.SetWidth(p.pageBitmapWidth); image.SetBpc(1); image.SetColorSpace(1); //TODO JBIG2 globals caching byte[] globals = sr.GetGlobal(true); //TODO due to the fact, that streams now may be transformed to indirect objects only on writing, //pdfStream.getDocument() cannot longer be the sign of inline/indirect images // in case inline image pdfStream.getDocument() will be null if (globals != null) { /*&& stream.getDocument() != null*/ IDictionary <String, Object> decodeParms = new Dictionary <String, Object>(); // PdfStream globalsStream = new PdfStream().makeIndirect(pdfStream.getDocument()); // globalsStream.getOutputStream().write(globals); decodeParms["JBIG2Globals"] = globals; image.decodeParms = decodeParms; } image.SetFilter("JBIG2Decode"); image.SetColorSpace(1); image.SetBpc(1); image.data = p.GetData(true); } catch (System.IO.IOException e) { throw new iText.IO.IOException(iText.IO.IOException.Jbig2ImageException, e); } }