List of usage examples for com.itextpdf.text.pdf PdfIndirectReference getNumber
public int getNumber()
From source file:cz.muni.pdfjbim.PdfImageExtractor.java
License:Apache License
/** * Extracts JBIG2Images from Input stream even if they are stored together with global dictionary in separate PDF object * doesn't work yet, its in development stage * @param is/*from www .j a va 2s . co m*/ * @throws PdfRecompressionException * @deprecated */ public void extractJbig2Images(InputStream is) throws PdfRecompressionException { if (is == null) { throw new IllegalArgumentException("InputStream not given"); } PdfReader pdfReader = null; try { pdfReader = new PdfReader(is); for (int i = 0; i <= pdfReader.getNumberOfPages(); i++) { PdfDictionary d = pdfReader.getPageN(i); PdfIndirectReference ir = d.getAsIndirectObject(PdfName.CONTENTS); PdfObject o = pdfReader.getPdfObject(ir.getNumber()); PdfStream stream = (PdfStream) o; PdfObject pdfsubtype = stream.get(PdfName.SUBTYPE); if (pdfsubtype != null && pdfsubtype.toString().equals(PdfName.IMAGE.toString())) { byte[] img = PdfReader.getStreamBytesRaw((PRStream) stream); OutputStream out = new FileOutputStream( new File("pdfRecompressor", String.format("%1$05d", i) + ".jpg")); out.write(img); out.flush(); out.close(); } } } catch (IOException ex) { log.error("IOException caught while trying to extract jbig2 images from PDF", ex); throw new PdfRecompressionException("IOException caught while trying to extract jbig2 images from PDF", ex); } finally { if (pdfReader != null) { pdfReader.close(); } } }