I have a V:Shape
that I am assuming has come from the conversion of a .Doc file to a .Docx file, but in the code I have written, I am wanting a DocumentFormat
I found a quick/simple way to do this - and I should have worked it out earlier!
The Shape
object has a ImageData
object as a descendant, so I checked for that, and ran it through an extra method to get the ImagePart
:
A.Blip pic = item.Descendants().FirstOrDefault();
ImageData imageData = item.Descendants().FirstOrDefault();
if (pic == null && imageData == null) //pictures are processed differently - they're an absolute s**t storm to code...
{
runToAmend.InsertAfterSelf(item.CloneNode(true));
}
else
{
if(pic != null)
{
runToAmend.InsertAfterSelf(CreateImageFromBlip(source, item, footerHeaderPart,pic));
}
else if (imageData != null)
{
runToAmend.InsertAfterSelf(CreateImageFromShape(source, item, footerHeaderPart, imageData));
}
}
Then created a new method - CreateImageFromShape(..)
which then calls the original CreateImageRun.
private Run CreateImageFromShape(WordprocessingDocument sourceDoc, Run sourceRun, OpenXmlPart headerFooterPart, ImageData imageData)
{
ImagePart p = sourceDoc.MainDocumentPart.GetPartById(imageData.RelationshipId) as ImagePart;
return CreateImageRun(sourceDoc, sourceRun, headerFooterPart, p);
}
Job done.