I’m trying to edit and replace embedded ole objects in presentations. I followed this instruction but it doesn’t work as I expected.
For example:
My pptx file has two embedded file a ppt and another pptx. There was no problem with the ppt I could edit and replace it but when I replaced the embedded pptx like this:
// Changing Ole frame object data
msout.Position = 0;
ole.ObjectData = msout.ToArray();
The replaced pptx Ole Object properties changed to this:
(MS PowerPoint 2016 cannot handled this embedded file after the replace, when I extracted the embedded file manually and replaced the .bin extension to .pptx I could open and see the changes in the file)
Can I replace all kinds of Ole Object data using the ObjectData property?
I tried another method to replace Ole Objects:
Get and edit the embedded file stream
Add a new Ole Object to the original position with AddOleObjectFrame
Remove the original Ole Object from the Slide
My problem with this, there will be the Changed Object image on the slide as you mentioned here. I wanted to change the image as it is in the example but there is no PictureId property in the IOleObjectFrame interface.
So my other question is: how could I change the added IOleObjectFrame image on the slide?
@erdeiga,
Thank you for the issue description. Could you also share a presentation sample for investigating the problem, please? It would be great to know the version of Aspose.Slides that you are using as well.
@Andrey_Potapov,
I attached the sample files, project and the requested infos.
When I replace the Ole objects there is no problem with the embedded ppt, doc and xls files but I cannot access the embedded pptx, docx, xlsx, pdf, png and txt files with MS Office.
Aspose.Slides 21.1
.Net Core 3.1
Linux environment
@erdeiga,
Thank you for the presentation samples, solution, and additional details. Did I understand correctly that the attached embeddedOleObjects.pptx file is the output file? Could you share the original PPTX file, please?
I am investigating your other questions.
PowerPoint cannot open the embedded oleObject2.bin (pptx) file from the attached embeddedOleObjects.pptx (before replacement). Could this file be already corrupted?
If I use this code snippet before the replace I can extract the embedded files without any problem (only the embedded image is corrupted) so I assume that there is no problem with the main file.
private static void SaveOleObjectToFile(in OleObjectFrame oleObjectFrame)
{
var dir = Directory.CreateDirectory("extracted_files");
string outPath = $"{dir.Name}{Path.DirectorySeparatorChar}extracted_{Guid.NewGuid()}{oleObjectFrame.EmbeddedFileExtension}";
var data = oleObjectFrame.EmbeddedFileData;
using FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write);
fstr.Write(data, 0, data.Length);
}
@erdeiga,
I have investigated your solution. Your code doesn’t work because you are reading embedded data from the EmbeddedFileData property, but you are writing changed data to the ObjectData property. Soon I will inform you how to do it right and answer the rest of the questions.
@Andrey_Potapov,
I managed to figure it out how to replace the Object changed image after I insert a new Ole Object to the a slide.
var newOleObject = embeddedOle.Slide.Shapes.AddOleObjectFrame(embeddedOle.X, embeddedOle.Y, embeddedOle.Width, embeddedOle.Height, redactedOleInfo);
//Replace Image that belong to the OleObject
if (!embeddedOle.IsObjectIcon)
{
//Get first slide thumbnail
Bitmap firstSlideAsImage = embeddedPresentation.Slides[0].GetThumbnail(1f, 1f);
//Replace the image that belongs to the new oleObject
newOleObject.SubstitutePictureFormat.Picture.Image.ReplaceImage(firstSlideAsImage);
}
//Remove old OleObject
embeddedOle.Slide.Shapes.Remove(embeddedOle);
But still it would be good to know how can I edit and replace an existing OleObjectFrame.EmbeddedFileData if it is possible.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.