Bug 55758

Summary: Problems embedding non-office OLE object into PPT SlideShow
Product: POI Reporter: Peter Adelmann <petera>
Component: HSLFAssignee: POI Developers List <dev>
Status: RESOLVED WONTFIX    
Severity: normal    
Priority: P2    
Version: 3.10-dev   
Target Milestone: ---   
Hardware: PC   
OS: All   
Bug Depends on: 55579    
Bug Blocks:    
Attachments: PPT Slideshow with single molfile embedded
OLE-implementation for Accelrys Draw .mol-file embedding

Description Peter Adelmann 2013-11-07 15:40:05 UTC
Created attachment 31026 [details]
PPT Slideshow with single molfile embedded

I have attached the code used for this prototype and both files although one is an empty ppt file which is pointless.  The file of interest is a mol file which is readable from accelerys draw version 4.1 (You may be able to d/l and install a trial of this software).  The object created from accelerys is called a mol file which is a representation of a molecule.  If you copy the mol file and paste it into a ppt slideshow it creates a ole object in the ppt file.  I have also attached(no I haven't only one attachement allowed) some java code which is based on PoiOleXlsInPpt a proof of concept out on the internet at 
http://stackoverflow.com/questions/2849102/embedding-hssfexcel-into-hslfppt-using-apache-poi/16879830#16879830.
The code uses an ppt/mol file and creates a new ppt and then attempts to create the ole object using poi's internals to embed the mol file and saves the new ppt file.  Based on our work with the code, the ppt file gets created, but then when trying to open the saved file with ppt. the application complains that the ppt file is corrupt and tries to repair but can't manange to repair the file and can't open the file.  So the ppt slideshow gets created but then can't be opened by ppt which suggests some is incorrect in the creation of the new file. Of course this use case works without a problem when the code which embeds the ole object is commented out.  So there's something in the embedding code which is not creating the object properly. Thanks.  I was going to try and attach the code but it doesn't look like multiple attachments are allowed so you got the ppt slideshow with a molfile embedded in it. I can provide our code if it makes things easier but I'm just trying to create a new ppt ss with the molfile embedded in it much like a copy and paste would do in windoze.  My real work is to get the molefile and embed into ppt but I can do that if we can just fix the issue with embedding the molefile into ppt. I can provide any additional info if needed.  Andreas Beeker was helping me on the user group and this bug is reported based on his suggestion.
Comment 1 Andreas Beeker 2013-11-25 22:32:45 UTC
Created attachment 31076 [details]
OLE-implementation for Accelrys Draw .mol-file embedding

The attachment contains a c# project to process a .mol file and generated
the neccessary ole object to be embedded by the also included java class.

An Accelrys Draw (AD) ole objects contains two streams.
1. "Contents": the bigger one, which is a concatenation of the following formats:
   - a mol-file
   - a skc-file
   - a mol-file, an ASCII-file, same as the 1st file, but with a line
     length (byte) as first char of the line
   - a emf-file
   - a wmf-file
   each file is prefixed with little endian integer, which specifies the file length
2. "\1Ole10Native": a "malformed" Ole10Native object, which is a subset of the
   Contents stream

as it works out, it's enough to embed the Contents stream

In the trial version, AD provides a few .net libraries and
JNI-Bridge consisting out of jar and two dlls. Although it's
possible to produce a few files of the mentioned above with
the bridge, it lacks emf/wmf support. There's a function
to copy data to and from the clipboard, which has the format 
of the contents stream, but it's not working.

After a bit of decompiling of the .net and .jar files,
I've started a small workaround c# project and it became visible
that the clipboard function always throws a "coinitialize hasn't
been called" error, no matter if I called coinitialize manually
or tweaked around the appartment model of the calling code.
The other functions work as designed.

So finally the solution is that c# helper, which generates the
contents stream and an emf preview image, and the embedding code
based on #55579.

It took a bit until the ensemble worked on Peters environment,
so in the rare case, that anybody else uses this code ;) ...
you might need to change the .net dll references and/or copy
various AD dlls to the local working dir.

As for the POI part this is only a very specific test, I'll
(try to) close this bug as "won't fix"