Hi rosh,
>> Now I need to convert the image format from WMF or EMF to PNG and replace the output in all the xml.
This forum is discussing about developer topics related to the Open XML Format SDK. For converting the image format from wmf or emf to png, it is more related with C#, and if you have issue about this, I will recommend you go to the forum below for help
about C# issue.
Reference:
https://social.msdn.microsoft.com/Forums/en-US/home?forum=csharpgeneral
For replacing the images with openxml, you could add an ImagePart to the document first, and then edit the Blip element to refer the new ImagePart. Some key code as below:
public void ReplaceImage(Blip blipElement, FileInfo newImg)
{
string rid = AddImagePart(newImg);
blipElement.Embed.Value = rid;
this.OnImagesChanged();
}
string AddImagePart(FileInfo newImg)
{
ImagePartType type = ImagePartType.Bmp ;
switch(newImg.Extension.ToLower())
{
case ".jpeg":
case ".jpg":
type = ImagePartType.Jpeg;
break;
case ".png":
type = ImagePartType.Png;
break;
default:
type = ImagePartType.Bmp;
break;
}
ImagePart newImgPart = Document.MainDocumentPart.AddImagePart(type);
using (FileStream stream = newImg.OpenRead())
{
newImgPart.FeedData(stream);
}
string rId = Document.MainDocumentPart.GetIdOfPart(newImgPart);
return rId;
}
|
The link below shows a code sample demonstrates how to replace images in an Office Word document using Openxml.
# Use Open XML to manipulate images in Word (CSManipulateImagesInWordDocument)
https://code.msdn.microsoft.com/office/CSManipulateImagesInWordDoc-312da7ef
Best Regards,
Edward
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.