Bug 56812 - XSLFPictureData reference to linked picture file
Summary: XSLFPictureData reference to linked picture file
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSLF (show other bugs)
Version: unspecified
Hardware: Macintosh All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-04 16:00 UTC by Geoff Wright
Modified: 2014-08-04 22:02 UTC (History)
1 user (show)



Attachments
Powerpoint file with three pictures. First picture is embedded, second picture is linked and embedded, third picture is only linked. (56.94 KB, application/vnd.openxmlformats-officedocument.presentationml.presentation)
2014-08-04 16:00 UTC, Geoff Wright
Details
Code to demonstrate null pointer error when picture is only linked (third picture in attached Powerpoint file). (1.16 KB, text/plain)
2014-08-04 16:03 UTC, Geoff Wright
Details

Note You need to log in before you can comment on or make changes to this bug.
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)