wordpress hit counter
Get image info with c#? - .Net - Development Tools - OpenXML Developer

Get image info with c#?

Development Tools

Discussions about working with Open XML using a wide range of development tools

Get image info with c#?

  • rated by 0 users
  • This post has 2 Replies |
  • 2 Followers
  • Hi, I'm new to openXML so go easy on me!

    Here is a snippet from a docx file I have

                    <w:drawing>
                        <wp:inline distT="0" distB="0" distL="0" distR="0">
                            <wp:extent cx="1352550" cy="1800225"/>
                            <wp:effectExtent l="19050" t="0" r="0" b="0"/>
                            <wp:docPr id="1" name="Picture 1" descr="Catherine Adams Photo"/>
                            <wp:cNvGraphicFramePr>
                                <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"/>
                            </wp:cNvGraphicFramePr>
                            <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                                <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
                                    <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
                                        <pic:nvPicPr>
                                            <pic:cNvPr id="0" name="Picture 1" descr="A Person Photo"/>
                                            <pic:cNvPicPr>
                                                <a:picLocks noChangeAspect="1" noChangeArrowheads="1"/>
                                            </pic:cNvPicPr>
                                        </pic:nvPicPr>
                                        <pic:blipFill>
                                            <a:blip r:embed="rId6" cstate="print"/>
                                            <a:srcRect/>
                                            <a:stretch>
                                                <a:fillRect/>
                                            </a:stretch>
                                        </pic:blipFill>
                                        <pic:spPr bwMode="auto">
                                            <a:xfrm>
                                                <a:off x="0" y="0"/>
                                                <a:ext cx="1352550" cy="1800225"/>
                                            </a:xfrm>
                                            <a:prstGeom prst="rect">
                                                <a:avLst/>
                                            </a:prstGeom>
                                            <a:noFill/>
                                            <a:ln w="9525">
                                                <a:noFill/>
                                                <a:miter lim="800000"/>
                                                <a:headEnd/>
                                                <a:tailEnd/>
                                            </a:ln>
                                        </pic:spPr>
                                    </pic:pic>
                                </a:graphicData>
                            </a:graphic>
                        </wp:inline>
                    </w:drawing>

    The docx has many images, this is just one. Using MainDocumentPart.ImageParts I can get all the ImageParts but I need to be able to get the "<pic:cNvPr id="0" name="Picture 1" descr="A Person Photo"/>" details, specifically the descr attribute. How do I go about this?

  • I don't think you can get the description data you need from the ImageParts collection.

    I would suggest using Linq to find all of the NonVisualDrawingProperties in the body of the document.  Like this:

    var drawingPropertiess = wordprocessingDocument.MainDocumentPart.Document.Body.Descendants().Where(openXmlElement => openXmlElement is DocumentFormat.OpenXml.Drawing.Pictures.NonVisualDrawingProperties);

    var photoDescriptions = drawingPropertiess.Select(drawingProp => ((DocumentFormat.OpenXml.Drawing.Pictures.NonVisualDrawingProperties)drawingProp).Description);

    This will give you an IEnumerable photoDescriptions of every description.
  • ^^^^^ This doesn't work.
Page 1 of 1 (3 items)