private void findPictures(List<EscherRecord> records) throws IOException, SAXException, TikaException { for (EscherRecord escherRecord : records) { if (escherRecord instanceof EscherBSERecord) { EscherBlipRecord blip = ((EscherBSERecord) escherRecord).getBlipRecord(); if (blip != null) { HSSFPictureData picture = new HSSFPictureData(blip); String mimeType = picture.getMimeType(); TikaInputStream stream = TikaInputStream.get(picture.getData()); // Handle the embeded resource extractor.handleEmbeddedResource( stream, null, null, mimeType, handler, true ); } } // Recursive call. findPictures(escherRecord.getChildRecords()); } } private class TikaFormatTrackingHSSFListener extends FormatTrackingHSSFListener {
/** * Performs a recursive search for pictures in the given list of escher records. * * @param escherRecords the escher records. * @param pictures the list to populate with the pictures. */ private void searchForPictures(List<EscherRecord> escherRecords, List<HSSFPictureData> pictures) { for(EscherRecord escherRecord : escherRecords) { if (escherRecord instanceof EscherBSERecord) { EscherBlipRecord blip = ((EscherBSERecord) escherRecord).getBlipRecord(); if (blip != null) { // TODO: Some kind of structure. HSSFPictureData picture = new HSSFPictureData(blip); pictures.add(picture); } } // Recursive call. searchForPictures(escherRecord.getChildRecords(), pictures); } }
for (HSSFPictureData pic : workbook.getAllPictures()) { InputStream in = new ByteArrayInputStream(pic.getData()); BufferedImage image = ImageIO.read(in); System.out.println(image.getWidth() + ":" + image.getHeight()); }
byte[] data = pictureData.getData(); String fileName = PATH + picture.getFileName() + "." + pictureData.suggestFileExtension(); File file = new File(fileName); try (FileOutputStream fop = new FileOutputStream(file)) {
/** * Return picture data for this shape * * @return picture data for this shape or {@code null} if picture wasn't embedded, i.e. external linked */ @Override public HSSFPictureData getPictureData(){ int picIdx = getPictureIndex(); if (picIdx == -1) { return null; } HSSFPatriarch patriarch = getPatriarch(); HSSFShape parent = getParent(); while(patriarch == null && parent != null) { patriarch = parent.getPatriarch(); parent = parent.getParent(); } if(patriarch == null) { throw new IllegalStateException("Could not find a patriarch for a HSSPicture"); } InternalWorkbook iwb = patriarch.getSheet().getWorkbook().getWorkbook(); EscherBSERecord bse = iwb.getBSERecord(picIdx); EscherBlipRecord blipRecord = bse.getBlipRecord(); return new HSSFPictureData(blipRecord); }
protected void copyPicturesToResultWorkbook() { List<HSSFPictureData> allPictures = templateWorkbook.getAllPictures(); for (HSSFPictureData allPicture : allPictures) { int i = resultWorkbook.addPicture(allPicture.getData(), Workbook.PICTURE_TYPE_JPEG); orderedPicturesId.add(i); } }
private void findPictures(List<EscherRecord> records) throws IOException, SAXException, TikaException { for (EscherRecord escherRecord : records) { if (escherRecord instanceof EscherBSERecord) { EscherBlipRecord blip = ((EscherBSERecord) escherRecord).getBlipRecord(); if (blip != null) { HSSFPictureData picture = new HSSFPictureData(blip); String mimeType = picture.getMimeType(); TikaInputStream stream = TikaInputStream.get(picture.getData()); // Handle the embeded resource extractor.handleEmbeddedResource( stream, null, null, mimeType, handler, true ); } } // Recursive call. findPictures(escherRecord.getChildRecords()); } } private class TikaFormatTrackingHSSFListener extends FormatTrackingHSSFListener {
/** * Performs a recursive search for pictures in the given list of escher records. * * @param escherRecords the escher records. * @param pictures the list to populate with the pictures. */ private void searchForPictures(List<EscherRecord> escherRecords, List<HSSFPictureData> pictures) { for(EscherRecord escherRecord : escherRecords) { if (escherRecord instanceof EscherBSERecord) { EscherBlipRecord blip = ((EscherBSERecord) escherRecord).getBlipRecord(); if (blip != null) { // TODO: Some kind of structure. HSSFPictureData picture = new HSSFPictureData(blip); pictures.add(picture); } } // Recursive call. searchForPictures(escherRecord.getChildRecords(), pictures); } }
protected void copyPicturesToResultWorkbook() { List<HSSFPictureData> allPictures = templateWorkbook.getAllPictures(); for (HSSFPictureData allPicture : allPictures) { int i = resultWorkbook.addPicture(allPicture.getData(), Workbook.PICTURE_TYPE_JPEG); orderedPicturesId.add(i); } }
private void findPictures(List<EscherRecord> records) throws IOException, SAXException, TikaException { for (EscherRecord escherRecord : records) { if (escherRecord instanceof EscherBSERecord) { EscherBlipRecord blip = ((EscherBSERecord) escherRecord).getBlipRecord(); if (blip != null) { HSSFPictureData picture = new HSSFPictureData(blip); String mimeType = picture.getMimeType(); TikaInputStream stream = TikaInputStream.get(picture.getData()); // Handle the embeded resource extractor.handleEmbeddedResource( stream, null, null, mimeType, handler, true ); } } // Recursive call. findPictures(escherRecord.getChildRecords()); } } private class TikaFormatTrackingHSSFListener extends FormatTrackingHSSFListener {
/** * Performs a recursive search for pictures in the given list of escher records. * * @param escherRecords the escher records. * @param pictures the list to populate with the pictures. */ private void searchForPictures(List<EscherRecord> escherRecords, List<HSSFPictureData> pictures) { for(EscherRecord escherRecord : escherRecords) { if (escherRecord instanceof EscherBSERecord) { EscherBlipRecord blip = ((EscherBSERecord) escherRecord).getBlipRecord(); if (blip != null) { // TODO: Some kind of structure. HSSFPictureData picture = new HSSFPictureData(blip); pictures.add(picture); } } // Recursive call. searchForPictures(escherRecord.getChildRecords(), pictures); } }
/** * Performs a recursive search for pictures in the given list of escher records. * * @param escherRecords the escher records. * @param pictures the list to populate with the pictures. */ private void searchForPictures(List<EscherRecord> escherRecords, List<HSSFPictureData> pictures) { for(EscherRecord escherRecord : escherRecords) { if (escherRecord instanceof EscherBSERecord) { EscherBlipRecord blip = ((EscherBSERecord) escherRecord).getBlipRecord(); if (blip != null) { // TODO: Some kind of structure. HSSFPictureData picture = new HSSFPictureData(blip); pictures.add(picture); } } // Recursive call. searchForPictures(escherRecord.getChildRecords(), pictures); } }
/** * Return picture data for this shape * * @return picture data for this shape */ public HSSFPictureData getPictureData(){ InternalWorkbook iwb = _patriarch._sheet.getWorkbook().getWorkbook(); EscherBlipRecord blipRecord = iwb.getBSERecord(_pictureIndex).getBlipRecord(); return new HSSFPictureData(blipRecord); } }
/** * Return picture data for this shape * * @return picture data for this shape */ public HSSFPictureData getPictureData(){ InternalWorkbook iwb = getPatriarch().getSheet().getWorkbook().getWorkbook(); EscherBlipRecord blipRecord = iwb.getBSERecord(getPictureIndex()).getBlipRecord(); return new HSSFPictureData(blipRecord); }
/** * Return picture data for this shape * * @return picture data for this shape or {@code null} if picture wasn't embedded, i.e. external linked */ @Override public HSSFPictureData getPictureData(){ int picIdx = getPictureIndex(); if (picIdx == -1) { return null; } HSSFPatriarch patriarch = getPatriarch(); HSSFShape parent = getParent(); while(patriarch == null && parent != null) { patriarch = parent.getPatriarch(); parent = parent.getParent(); } if(patriarch == null) { throw new IllegalStateException("Could not find a patriarch for a HSSPicture"); } InternalWorkbook iwb = patriarch.getSheet().getWorkbook().getWorkbook(); EscherBSERecord bse = iwb.getBSERecord(picIdx); EscherBlipRecord blipRecord = bse.getBlipRecord(); return new HSSFPictureData(blipRecord); }