3

I need to get relationship id of a Drawing object to extract images from Word using OpenXml. I saw Replace image in word doc using OpenXML and I'm using this code now:

string imageId = "default value";
Blip blipElement = selectedImage.Descendants<Blip>().First();
if (blipElement != null) {
    imageId = blipElement.Embed.Value;
}
document.MainDocumentPart.GetPartById(imageId);

Works perfectly for usual images, but doesn't work for powerpoint slides which are stored as EMF images inside docx, because EMF Drawing's don't have Blip. But they have ImageParts just like the usual images and I can see them. So, the question is, how do I find an imageId from a Drawing to get those EMF ImageParts? Unfortunately, I can't extract images the other way, because I'm trying to inject my code into a huge existing codebase, so I need to get it from a Drawing object.

Community
  • 1
  • 1
ptkvsk
  • 2,096
  • 1
  • 25
  • 47
  • 1
    Could you provide a sample document? How is the powerpoint presentation inserted into the word document? Via the menu Insert->Object? – Hans Nov 07 '13 at 18:14
  • Yes, I did it in Word 2010 via Insert->Object->Microsoft PowerPoint Slide. The weird thing is: yesterday it generated a drawing without blip once, now it generates a completely different thing: with that actually contains rId I'm looking for. Now I'm trying to understand why and how it generated drawing without blip at the first place... Here are the xml examples. 1. Drawing with blip (embedded image): http://pastebin.com/Qwj9ewLP 2. Drawing without blip (the reason why I asked the question): http://pastebin.com/9vyBJDLh 3. Now: http://pastebin.com/JJ3piJi3 – ptkvsk Nov 08 '13 at 09:42
  • 1
    I will have a look at your documents. Give me a few hours. – Hans Nov 08 '13 at 10:08
  • Thx, Hans I've just found that this question is wrong :( The Drawing object is NOT generated for Insert->Object->Slide. My document №2 is actually a Chart inserted through Insert->Chart, not a PP slide. And there is no EMF in /media/ folder for that chart. – ptkvsk Nov 08 '13 at 10:13

1 Answers1

0

Ok, so the problem was that I was looking at a wrong thing. The Drawing without a Blip that I saw was actually a chart (Insert->Chart), not a PP slide. Here is the xml for it: http://pastebin.com/9vyBJDLh There is a chart relation for it pointing to chart1.xml in /charts/ folder. And there is no EMF generated for the chart.

The slides inserted via "Insert->Object->Microsoft PowerPoint Slide" have completely different format, they are not Drawings and must be handled separately: http://pastebin.com/JJ3piJi3 and rId in imageData element actually points to EMF file under /media/ folder.

ptkvsk
  • 2,096
  • 1
  • 25
  • 47