I have a w:pict/Picture
within a run, to which I am trying to get the Stream
of, to copy it to another part of the document.
I've taken the relationship (Id = r1
), and loaded the part from the MainDocumentPart
, to be given a CustomXmlPart
(which doesn't seem right, but the XML suggests it is)... but upon checking my Relationships.xml, the part Id links to bibliography not image data....
Thoughts?
internal static Run CreateImageFromPicObj(WordprocessingDocument sourceDoc, Run sourceRun, OpenXmlPart headerFooterPart, Picture pic)
{
ImageData data = pic.Descendants<ImageData>().FirstOrDefault();
OpenXmlPart customP = sourceDoc.MainDocumentPart.GetPartById(data.RelationshipId);
return CreateCustomImageRun(sourceDoc, sourceRun, headerFooterPart, customP, pic);
}
private static Run CreateCustomImageRun(WordprocessingDocument sourceDoc, Run sourceRun, OpenXmlPart headerFooterPart, OpenXmlPart customP, Picture pic)
{
Bitmap image = new Bitmap(customP.GetStream());
...omitted - fails on this line
}
RunCode
<w:p w:rsidR="00624DF2" w:rsidRDefault="009E3005" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:pPr>
<w:pStyle w:val="OfficeAddress" />
<w:rPr>
<w:sz w:val="10" />
</w:rPr>
</w:pPr>
<w:r>
<w:pict>
<v:shapetype id="_x0000_t75" coordsize="21600,21600" filled="f" stroked="f" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml">
<v:stroke joinstyle="miter" />
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0" />
<v:f eqn="sum @0 1 0" />
<v:f eqn="sum 0 0 @1" />
<v:f eqn="prod @2 1 2" />
<v:f eqn="prod @3 21600 pixelWidth" />
<v:f eqn="prod @3 21600 pixelHeight" />
<v:f eqn="sum @0 0 1" />
<v:f eqn="prod @6 1 2" />
<v:f eqn="prod @7 21600 pixelWidth" />
<v:f eqn="sum @8 21600 0" />
<v:f eqn="prod @7 21600 pixelHeight" />
<v:f eqn="sum @10 21600 0" />
</v:formulas>
<v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f" />
<o:lock v:ext="edit" aspectratio="t" />
</v:shapetype>
<v:shape id="_x0000_s2049" style="position:absolute;left:0;text-align:left;margin-left:395.25pt;margin-top:3.6pt;width:87pt;height:50.45pt;z-index:251657728" type="#_x0000_t75" xmlns:v="urn:schemas-microsoft-com:vml">
<v:imagedata o:title="" r:id="rId1" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:o="urn:schemas-microsoft-com:office:office" />
</v:shape>
</w:pict>
</w:r>
</w:p>
Document.xml.rels - ommited for brevity
<?xml version="1.0" encoding="UTF-8"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml" Target="../customXml/item1.xml" />
</Relationships>
CustomXml/item.xml
<b:Sources SelectedStyle="\APASixthEditionOfficeOnline.xsl" StyleName="APA" Version="6" xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns="http://schemas.openxmlformats.org/officeDocument/2006/bibliography"></b:Sources>