简体   繁体   中英

How to get an image id of a Drawing with OpenXml (MS Word)?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM