Support different file types for Ole Objects in Mac

Hi,
I hope you are well,

I’m trying to insert different file types as an OleObjects into word but I get a message in Word file that, for example, the embedded PDF file cannot be opened.
Does Aspose support any file types to embed in Word?

Please find the attached code herein which can be used in your test scenario.
aspose-ole-objects.zip (173.0 KB)

Regards,
Behrouz

@behrouz

We have opened the OLE (PDF and Word) embedded in output.docx. We have not faced any issue. Both files are opened without any issue. Could you please share some more detail about your query? We will then provide you more information on it.

@tahir.manzoor
Thanks for your reply,

When | try to open the embedded OLE (PDF) in output.docx I get an error.
Is this an office related error? If so, could you please tell me how to fix it?
I attach the snapshot of the error here.
Screen Shot 2019-05-08 at 23.32.07.jpg (241.9 KB)

–To be mentioned that I’m testing it on MacOS.

thanks

@behrouz

You are using Aspose.Words in evaluation mode. We suggest you please get the 30 days temporary license and apply it. Please use the latest version of Aspose.Words for Java 19.5. If you still face problem, please ZIP and attach your output document here for further testing.

@tahir.manzoor

Please find the attached document here for further testing.
output.docx.zip (33.8 KB)

Regards,
Behrouz

@behrouz

You used the old version of Aspose.Words 19.3 to generate the document. Please try the latest version of Aspose.Words 19.5.

We have attached two documents with this post. One is generated by Aspose.Words 19.5 and other is generated by MS Word 2016. Please open the OLE at your end and let us know how it goes on your side. Please share the screenshots of output. Docs.zip (70.5 KB)

@tahir.manzoor

I tested the generated docs in Windows and it seems to work correctly. I think, MS Office in Mac only supports MS Products.
I get another error with large files. The problem happens when I’m trying to embed large files. (in my scenario two files with 500MB size).

    Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at com.aspose.words.internal.zz6P.zzSp(Unknown Source)
at com.aspose.words.internal.zz6P.zzSq(Unknown Source)
at com.aspose.words.internal.zz6P.write(Unknown Source)
at com.aspose.words.internal.zzX.zzZ(Unknown Source)
at com.aspose.words.internal.zzRG.zzZ(Unknown Source)
at com.aspose.words.internal.zzRG.zzY(Unknown Source)
at com.aspose.words.internal.zzRG.zzZ(Unknown Source)
at com.aspose.words.internal.zzRG.zzL(Unknown Source)
at com.aspose.words.zz88.zzZ(Unknown Source)
at com.aspose.words.zz88.zzu(Unknown Source)
at com.aspose.words.zz88.zzv(Unknown Source)
at com.aspose.words.zz88.visitShapeEnd(Unknown Source)
at com.aspose.words.Shape.zzY(Unknown Source)
at com.aspose.words.CompositeNode.acceptCore(Unknown Source)
at com.aspose.words.Shape.accept(Unknown Source)
at com.aspose.words.CompositeNode.acceptChildren(Unknown Source)
at com.aspose.words.CompositeNode.acceptCore(Unknown Source)
at com.aspose.words.Paragraph.accept(Unknown Source)
at com.aspose.words.CompositeNode.acceptChildren(Unknown Source)
at com.aspose.words.CompositeNode.acceptCore(Unknown Source)
at com.aspose.words.Body.accept(Unknown Source)
at com.aspose.words.zz88.zzV(Unknown Source)
at com.aspose.words.zz89.zzZNh(Unknown Source)
at com.aspose.words.zz89.zzZNi(Unknown Source)
at com.aspose.words.zz88.write(Unknown Source)
at com.aspose.words.zz6Y.zzZNh(Unknown Source)
at com.aspose.words.zz6Y.zzZ(Unknown Source)
at com.aspose.words.zzZGP.zzZ(Unknown Source)
at com.aspose.words.Document.zzZ(Unknown Source)
at com.aspose.words.Document.zzZ(Unknown Source)
at com.aspose.words.Document.save(Unknown Source)
at com.aspose.words.Document.save(Unknown Source)

Is there any way to avoid this problem?

Regards,
Behrouz

@behrouz

Please note that performance and memory usage all depend on complexity and size of the documents you are generating.

In terms of memory, Aspose.Words does not have any limitations. If you’re loading huge Word documents into Aspose.Words’ DOM, more memory would be required. This is because during processing, the document needs to be held wholly in memory. Usually, Aspose.Words needs 10 times more memory than the original document size to build a DOM in the memory.

We suggest you please increase the heap size and use SaveOptions.MemoryOptimization property. Setting this property to true can significantly decrease memory consumption while saving large documents at the cost of slower saving time. Hope this helps you.

@tahir.manzoor
Thanks for your reply,

We just came up with one possible approach to solve this problem without enforcing users to increase the heap memory.
The solution is that first, we insert a fake small file through Aspose API into the document and in the end, we replace the embedded files with the original files in the final document.

  1. The question is that, Is there any way to get the name of embedded files through Aspose?

  2. Another question is whether exist an API in Aspose to get Relationship id of embedded objects? If so, maybe we can find a way to create a map between the original file names and embedded file names through that API.
    For example, in the following oleObject in document.xml file, the relationship id is rId14

    <w:p w:rsidR=“00A77B3E”>
    <w:r>
    <w:object>
    <v:shape id="_x0000_i1034" type="#_x0000_t75" style=“width:79.69pt;height:51.28pt” o:oleicon=“t” o:ole="">
    <v:imagedata r:id=“rId4” o:title=""/>
    </v:shape>
    <o:OLEObject Type=“Embed” ProgID=“Word.Document.12” ShapeID="_x0000_i1034" DrawAspect=“Icon” ObjectID="_9" r:id=“rId14”/>
    </w:object>
    </w:r>
    </w:p>

In this case, we would have to convert original files to embedded object types. Could you please tell me what would be the best solution or library to generate an oleObject?

  1. I also see that the embedded files are named like oleObject1.bin, oleObject2.bin,…
    Is always this naming pattern happening?

Regards,
Behrouz

@behrouz

You can bookmark the OLE object and name the bookmark same as file name.

We suggest you please use the linked OLE objects instead of embedded OLE objects.

Please note that Aspose.Words mimics the behavior of MS Word. If you embed the same files in the Word document and unzip the document, you will get the same output.