Hello,
Iam trying to convert my word to xml, everything is fine but the font is not saved. Iam using “David” font and getting “Times New Roman”
If you look at the xml file attached you can see it includes the following line:
<w:font w:name=“Times New Roman”>
Iam trying to change it in my code… how can I change/add elements at the xml file?
and how can I save the word as Word 2003 XML Document?
public void Post()
{
var file = HttpContext.Current.Request.Files.Count > 0 ?
HttpContext.Current.Request.Files[0] : null;
MemoryStream xmlStream = new MemoryStream();
using (MemoryStream docStream = new MemoryStream())
{
file.InputStream.CopyTo(docStream);
file.InputStream.Dispose();
Document xml = new Document(docStream);
xml.Save(xmlStream, SaveFormat.WordML);
string xmlText = Encoding.UTF8.GetString(xmlStream.GetBuffer());
xmlText = xmlText.Replace("Times New Roman", "David");
xmlStream = new MemoryStream();
var writer = new StreamWriter(xmlStream);
writer.Write(xmlText);
writer.Flush();
xmlStream.Position = 0;
xml.Save(@"C:\Users\Puno\Desktop\file.xml", SaveFormat.WordML);
}
}
here is the word iam converting from and the xml iam getting
Desktop.zip (11.3 KB)