Replies: 3 comments 2 replies
-
I have managed to implement it as the next var svgString = @"
<svg xmlns=""http://www.w3.org/2000/svg"" style=""border:solid 1px black"" >
<rect x=""0pt"" y=""0pt"" width=""100pt"" height=""80pt"" fill=""lime"" ></rect>
<g id=""eye"" stroke=""black"" stroke-width=""2pt"" >
<ellipse cx=""50pt"" cy=""40pt"" rx=""40pt"" ry=""20pt"" fill=""white""></ellipse>
<circle cx=""50pt"" cy=""40pt"" r=""20pt"" fill=""#66F""></circle>
<circle cx=""50pt"" cy=""40pt"" r=""10pt"" fill=""black""></circle>
<line x1=""10"" x2=""90"" y1=""40"" y2=""40"" />
<line x1=""50"" x2=""50"" y1=""20"" y2=""60"" />
</g>
</svg>";
var component = Document.ParseHtml("", new MemoryStream(Encoding.UTF8.GetBytes(svgString)), ParseSourceType.Template);
HTMLFragmentWrapper w = (HTMLFragmentWrapper)component;
var svg = w.Content[0]; but do not like an idea of hardcoded type casting and Document.ParseHtml method invocation looks overcomplicated |
Beta Was this translation helpful? Give feedback.
-
Hi Pavlo As the svgString is valid XML is probably more efficient and easier to use the Parse methods on the Document class, rather than ParseHtml, and this has more overloads. But all visual components now include the DataContent property. This can be used to set string values that will be parsed as xml during the document processing. These properties were added as part of this discussion #96 I have added a unit test with 3 examples in Scryber.UnitTests/Html/SVGParsing_Tests and attached the resulting document. But the code is as follows....
|
Beta Was this translation helpful? Give feedback.
-
Have got a problem to convert the next SVG image
It fails with the next error
|
Beta Was this translation helpful? Give feedback.
-
Hi,
I use code approach for building document. And now I need to embed an svg image.
Im my case svg image comes as string, so I need to convert it somehow to the Component instance.
Documentation shows only how to use html templates but not how to do that programatically.
Beta Was this translation helpful? Give feedback.
All reactions