use of org.apache.poi.hslf.usermodel.HSLFPictureData in project tika by apache.
the class HSLFExtractor method handleSlideEmbeddedPictures.
private void handleSlideEmbeddedPictures(HSLFSlideShow slideshow, XHTMLContentHandler xhtml) throws TikaException, SAXException, IOException {
for (HSLFPictureData pic : slideshow.getPictureData()) {
String mediaType;
switch(pic.getType()) {
case EMF:
mediaType = "image/emf";
break;
case WMF:
mediaType = "image/wmf";
break;
case DIB:
mediaType = "image/bmp";
break;
default:
mediaType = pic.getContentType();
break;
}
byte[] data = null;
try {
data = pic.getData();
} catch (Exception e) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata);
continue;
}
try (TikaInputStream picIs = TikaInputStream.get(data)) {
handleEmbeddedResource(picIs, null, null, mediaType, xhtml, false);
}
}
}
use of org.apache.poi.hslf.usermodel.HSLFPictureData in project poi by apache.
the class ImageExtractor method main.
public static void main(String[] args) throws IOException {
if (args.length < 1) {
System.err.println("Usage:");
System.err.println("\tImageExtractor <file>");
return;
}
HSLFSlideShow ppt = new HSLFSlideShow(new HSLFSlideShowImpl(args[0]));
//extract all pictures contained in the presentation
int i = 0;
for (HSLFPictureData pict : ppt.getPictureData()) {
// picture data
byte[] data = pict.getData();
PictureType type = pict.getType();
FileOutputStream out = new FileOutputStream("pict_" + i++ + type.extension);
out.write(data);
out.close();
}
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFPictureData in project poi by apache.
the class TestDocumentEncryption method cryptoAPIDecryption.
@Test
public void cryptoAPIDecryption() throws Exception {
// taken from a msdn blog:
// http://blogs.msdn.com/b/openspecification/archive/2009/05/08/dominic-salemno.aspx
Biff8EncryptionKey.setCurrentUserPassword("crypto");
NPOIFSFileSystem fs = new NPOIFSFileSystem(slTests.getFile("cryptoapi-proc2356.ppt"));
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(fs);
HSLFSlideShow ss = new HSLFSlideShow(hss);
HSLFSlide slide = ss.getSlides().get(0);
String rawText = HSLFTextParagraph.getRawText(slide.getTextParagraphs().get(0));
assertEquals("Dominic Salemno", rawText);
String[][] picCmp = { { "0", "nKsDTKqxTCR8LFkVVWlP9GSTvZ0=" }, { "95163", "SuNOR+9V1UVYZIoeD65l3VTaLoc=" }, { "100864", "Ql3IGrr4bNq07ZTp5iPg7b+pva8=" }, { "714114", "8pdst9NjBGSfWezSZE8+aVhIRe0=" }, { "723752", "go6xqW7lvkCtlOO5tYLiMfb4oxw=" }, { "770128", "gZUM8YqRNL5kGNfyyYvEEernvCc=" }, { "957958", "CNU2iiqUFAnk3TDXsXV1ihH9eRM=" } };
MessageDigest md = CryptoFunctions.getMessageDigest(HashAlgorithm.sha1);
List<HSLFPictureData> pd = hss.getPictureData();
int i = 0;
for (HSLFPictureData p : pd) {
byte[] hash = md.digest(p.getData());
assertEquals(Integer.parseInt(picCmp[i][0]), p.getOffset());
assertEquals(picCmp[i][1], Base64.encodeBase64String(hash));
i++;
}
DocumentEncryptionAtom dea = hss.getDocumentEncryptionAtom();
POIFSFileSystem fs2 = ((CryptoAPIDecryptor) dea.getEncryptionInfo().getDecryptor()).getSummaryEntries(fs.getRoot(), "EncryptedSummary");
PropertySet ps = PropertySetFactory.create(fs2.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME);
assertTrue(ps.isSummaryInformation());
assertEquals("RC4 CryptoAPI Encryption", ps.getProperties()[1].getValue());
ps = PropertySetFactory.create(fs2.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
assertTrue(ps.isDocumentSummaryInformation());
assertEquals("On-screen Show (4:3)", ps.getProperties()[1].getValue());
ss.close();
fs.close();
fs2.close();
}
use of org.apache.poi.hslf.usermodel.HSLFPictureData in project poi by apache.
the class TestShapes method shapeGroup.
/**
* Test adding shapes to <code>ShapeGroup</code>
*/
@Test
public void shapeGroup() throws IOException {
HSLFSlideShow ss = new HSLFSlideShow();
HSLFSlide slide = ss.createSlide();
Dimension pgsize = ss.getPageSize();
HSLFGroupShape group = new HSLFGroupShape();
group.setAnchor(new Rectangle2D.Double(0, 0, pgsize.getWidth(), pgsize.getHeight()));
slide.addShape(group);
HSLFPictureData data = ss.addPicture(_slTests.readFile("clock.jpg"), PictureType.JPEG);
HSLFPictureShape pict = new HSLFPictureShape(data, group);
pict.setAnchor(new Rectangle2D.Double(0, 0, 200, 200));
group.addShape(pict);
HSLFLine line = new HSLFLine(group);
line.setAnchor(new Rectangle2D.Double(300, 300, 500, 0));
group.addShape(line);
//serialize and read again.
ByteArrayOutputStream out = new ByteArrayOutputStream();
ss.write(out);
out.close();
ss.close();
ByteArrayInputStream is = new ByteArrayInputStream(out.toByteArray());
ss = new HSLFSlideShow(is);
is.close();
slide = ss.getSlides().get(0);
List<HSLFShape> shape = slide.getShapes();
assertEquals(1, shape.size());
assertTrue(shape.get(0) instanceof HSLFGroupShape);
group = (HSLFGroupShape) shape.get(0);
List<HSLFShape> grshape = group.getShapes();
assertEquals(2, grshape.size());
assertTrue(grshape.get(0) instanceof HSLFPictureShape);
assertTrue(grshape.get(1) instanceof HSLFLine);
pict = (HSLFPictureShape) grshape.get(0);
assertEquals(new Rectangle2D.Double(0, 0, 200, 200), pict.getAnchor());
line = (HSLFLine) grshape.get(1);
assertEquals(new Rectangle2D.Double(300, 300, 500, 0), line.getAnchor());
ss.close();
}
use of org.apache.poi.hslf.usermodel.HSLFPictureData in project poi by apache.
the class TestOleEmbedding method testEmbedding.
@Test
public void testEmbedding() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
File pict = POIDataSamples.getSlideShowInstance().getFile("clock.jpg");
HSLFPictureData pictData = ppt.addPicture(pict, PictureType.JPEG);
InputStream is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("Employee.xls");
POIFSFileSystem poiData1 = new POIFSFileSystem(is);
is.close();
int oleObjectId1 = ppt.addEmbed(poiData1);
HSLFSlide slide1 = ppt.createSlide();
OLEShape oleShape1 = new OLEShape(pictData);
oleShape1.setObjectID(oleObjectId1);
slide1.addShape(oleShape1);
oleShape1.setAnchor(new Rectangle2D.Double(100, 100, 100, 100));
// add second slide with different order in object creation
HSLFSlide slide2 = ppt.createSlide();
OLEShape oleShape2 = new OLEShape(pictData);
is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SimpleWithImages.xls");
POIFSFileSystem poiData2 = new POIFSFileSystem(is);
is.close();
int oleObjectId2 = ppt.addEmbed(poiData2);
oleShape2.setObjectID(oleObjectId2);
slide2.addShape(oleShape2);
oleShape2.setAnchor(new Rectangle2D.Double(100, 100, 100, 100));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ppt.write(bos);
ppt = new HSLFSlideShow(new ByteArrayInputStream(bos.toByteArray()));
OLEShape comp = (OLEShape) ppt.getSlides().get(0).getShapes().get(0);
byte[] compData = IOUtils.toByteArray(comp.getObjectData().getData());
bos.reset();
poiData1.writeFilesystem(bos);
byte[] expData = bos.toByteArray();
assertArrayEquals(expData, compData);
poiData1.close();
poiData2.close();
ppt.close();
}
Aggregations