List of usage examples for com.itextpdf.text.pdf PdfStream get
public PdfObject get(final PdfName key)
PdfObject
associated to the specified key. 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 w ww. ja v a2 s . c o 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(); } } }
From source file:org.gmdev.pdftrick.engine.CheckFiles.java
License:Open Source License
/** * Check the number of images contained in the file's selection, if == 0 return false. * @param filesVett//from w ww. j a va2 s.c om * @param messages * @return TRUE if the there is at least one image in the PDF files selection. */ private boolean checkNumberImages(ArrayList<File> filesVett, Properties messages) { boolean checkNumImg = false; Iterator<File> ite = filesVett.iterator(); while (ite.hasNext()) { File item = ite.next(); PdfReader reader = null; try { if (namePwd.containsKey(item.getName())) { reader = new PdfReader(item.getPath(), namePwd.get(item.getName()).getBytes()); } else { reader = new PdfReader(item.getPath()); } for (int i = 0; i < reader.getXrefSize(); i++) { PdfObject pdfobj = reader.getPdfObject(i); if (pdfobj == null || !pdfobj.isStream()) { continue; } PdfStream stream = (PdfStream) pdfobj; PdfObject pdfsubtype = stream.get(PdfName.SUBTYPE); if (pdfsubtype != null && pdfsubtype.toString().equals(PdfName.IMAGE.toString())) { checkNumImg = true; break; } } if (checkNumImg) { break; } } catch (IOException e) { logger.error("Exception", e); PdfTrickMessages.append("ERROR", Consts.SENDLOG_MSG); } } if (!checkNumImg) { PdfTrickMessages.append("WARNING", messages.getProperty("tmsg_21")); } return checkNumImg; }
From source file:pdfextract.ExtractInfo.java
public void extractImagesInfo() { try {/*from w w w . j av a 2 s . c o m*/ PdfReader chartReader = new PdfReader("vv.pdf"); for (int i = 0; i < chartReader.getXrefSize(); i++) { PdfObject pdfobj = chartReader.getPdfObject(i); if (pdfobj != null && pdfobj.isStream()) { PdfStream stream = (PdfStream) pdfobj; PdfObject pdfsubtype = stream.get(PdfName.SUBTYPE); //System.out.println("Stream subType: " + pdfsubtype); if (pdfsubtype != null && pdfsubtype.toString().equals(PdfName.IMAGE.toString())) { byte[] image = PdfReader.getStreamBytesRaw((PRStream) stream); Image imageObject = Image.getInstance(image); System.out.println("Resolution" + imageObject.getDpiX()); System.out.println("Height" + imageObject.getHeight()); System.out.println("Width" + imageObject.getWidth()); } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:pdfextract.ExtractInfo.java
public void imageNew() throws IOException { PdfReader reader;/*from w ww . j a v a2 s . c o m*/ File file = new File("vv.pdf"); reader = new PdfReader(file.getAbsolutePath()); for (int i = 0; i < reader.getXrefSize(); i++) { PdfObject pdfobj = reader.getPdfObject(i); if (pdfobj == null || !pdfobj.isStream()) { continue; } PdfStream stream = (PdfStream) pdfobj; PdfObject pdfsubtype = stream.get(PdfName.SUBTYPE); if (pdfsubtype != null && pdfsubtype.toString().equals(PdfName.IMAGE.toString())) { byte[] img = PdfReader.getStreamBytesRaw((PRStream) stream); FileOutputStream out = new FileOutputStream( new File(file.getParentFile(), String.format("%1$05d", i) + ".jpg")); out.write(img); out.flush(); out.close(); } } }