|Summary:||XSLFPictureData reference to linked picture file|
|Product:||POI||Reporter:||Geoff Wright <geoff>|
|Component:||XSLF||Assignee:||POI Developers List <dev>|
Powerpoint file with three pictures. First picture is embedded, second picture is linked and embedded, third picture is only linked.
Code to demonstrate null pointer error when picture is only linked (third picture in attached Powerpoint file).
Description Geoff Wright 2014-08-04 16:00:16 UTC
Created attachment 31873 [details] Powerpoint file with three pictures. First picture is embedded, second picture is linked and embedded, third picture is only linked. When adding a picture to a PowerPoint presentation, you can embed the file or link to it. The embedded filename can be accessed using: XSLFPictureData data = ((XSLFPictureShape) shape).getPictureData(); System.out.println(data.getFileName()); output: org.apache.poi.xslf.usermodel.XSLFPictureShape@654df764 image7.png However, when the picture is not embedded but inserted only as a "link to file", there is no data available and the above code produces a null pointer exception. Is it possible to add a reference to the linked picture file ?
Comment 1 Geoff Wright 2014-08-04 16:03:30 UTC
Created attachment 31874 [details] Code to demonstrate null pointer error when picture is only linked (third picture in attached Powerpoint file). The third picture in the referenced Powerpoint file is a linked picture (not embedded). data.getFilename() returns a null pointer exception but it would be useful if it returned the name of the linked picture file.
Comment 2 Nick Burch 2014-08-04 21:35:28 UTC
Thanks for this, I've used it to add a disabled unit test in r1615803.
Comment 3 Nick Burch 2014-08-04 22:02:24 UTC
Fixed in r1615812. XSLFPictureShape now provides a method isExternalLinkedPicture(), which lets you check if it'll have a picture data or not. If not, you can use getPictureLink() to get the URI of the externally linked image. (You can't get a XSLFPictureData as the data isn't in the pptx file)