Page 1 of 1

Embedding PPT in Docx

PostPosted: Mon Dec 15, 2014 8:18 pm
by Goutham Reddy
Hi,

We have tried embedding a PPT into document using below code. But the generated document doesn't open the embedded PPT on click of OLE icon.

Code: Select all

package samples.OLE.java;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
import com.plutext.ole.EmbeddingType;
import com.plutext.ole.OleHelperDocx;

public class Docx_ole_Doc {

   static org.docx4j.wml.ObjectFactory wmlObjectFactory = org.docx4j.jaxb.Context.getWmlObjectFactory();
   
   public static void main(String[] args) throws Exception {
      WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
      MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
      EmbeddingType embeddingType = EmbeddingType.PPT;
      
   byte[] contentBytes = FileUtils.readFileToByteArray(new File("C:\\Users\\myUser\\Documents\\Test.ppt" ));
      // the image on the document surface
      byte[] imageBytes = FileUtils.readFileToByteArray(new File("C:\\Users\\myUser\\Pictures\\test.jpg" ));
      
      // if you know your image mime type, you can avoid image introspection (which avoids temp file creation)
      String mime = "image/jpg"; // .. otherwise, set this to null
      
      // position in docx content list
      int index = -1; // place at end
            
      // Both link and embed require this
        String filepath = "C:\\Users\\myUser\\pictures\\OUT_doc_embedded.docx";    // typically the original file location
      String caption = "file.doc"; // can be anything, but may be used if displaying content rather than icon
      String command ="C:\\Users\\myUser\\AppData\\Local\\Temp\\OUT_doc_embedded_temp.docx"; // a temp file location
      
         OleHelperDocx OleHelperDocx = new OleHelperDocx(wordMLPackage);
      OleHelperDocx.embed(index, embeddingType, caption, filepath, command, contentBytes, imageBytes);

      // Save the resulting docx
      wordMLPackage.save(new File("C:\\Users\\myUser\\pictures\\OUT_doc_embedded.docx"));
      
   }
      
   


}



Can you please let us know if we are missing anything here and also help us in embedding PPT in Docx file.

Thanks.

Re: Embedding PPT in Docx

PostPosted: Mon Dec 15, 2014 9:48 pm
by jason
For assistance with the Enterprise Edition, please contact Plutext by email.

Please advise what version of Office you have installed, and ideally, supply a copy of the generated docx.