0

I am exporting image via svg. Below is my c# code.

string chartTitle = "ABC 50 µG";
XmlDocument xd = new XmlDocument();
xd.XmlResolver = null;

string chartSvg = "<svg><text x=\"1\" y=\"15\" font-size=\"14\" font-weight='bold' font-family=\"Arial\" ><tspan x=\"458\" dy=\"10\"> " + chartTitle + "</tspan></text></svg>"

xd.LoadXml(chartSvg);
svgGraph = Svg.SvgDocument.Open(xd);

I am getting error Invalid character in the given encoding. Line 1, position 110. at last line above due to µ symbol in my chartTitle.

Please help, how can i tackle this

RobertKing
  • 1,853
  • 8
  • 30
  • 54

2 Answers2

0

You can try like this:

var byteArr = Encoding.ASCII.GetBytes(svgContents);
using (var str = new MemoryStream(byteArr))
{
   var svgDoc = SvgDocument.Open(str);
   var bitmap = svgDoc.Draw();
   bitmap.Save(path, ImageFormat.Png);
}

Also look at the SVG Engine codeplex

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
0

Got the solution with below code.

string chartTitle = "ABC 50 µG";
XmlDocument xd = new XmlDocument();
xd.XmlResolver = null;

string chartSvg = "<svg><text x=\"1\" y=\"15\" font-size=\"14\" font-weight='bold' font-family=\"Arial\" ><tspan x=\"458\" dy=\"10\"> " + chartTitle + "</tspan></text></svg>"

xd.LoadXml(chartSvg);    
XmlDeclaration obj = xd.CreateXmlDeclaration("1.0", "ISO-8859-1", "yes");
XmlElement root = xd.DocumentElement;
xd.InsertBefore(obj, root);
svgGraph = Svg.SvgDocument.Open(xd);
RobertKing
  • 1,853
  • 8
  • 30
  • 54