Help with example

Dec 17, 2008 at 8:59 PM

Using the following code in a WinForms application I get the listed error.
The last line generates an "NullReferenceException was unhandled",
"Object reference not set to an instance of an object" error.
Any ideas?

Thanks.

Larry

SvgDocument sd = new SvgDocument();

sd= SvgDocument.Open(@"D:\svg\pie.svg");

sd.Draw().Save(@"d:\svg\pie.jpg", ImageFormat.Jpeg);

Coordinator
Dec 17, 2008 at 11:17 PM
Hi Larry,

Hmm now there is no reason why it shouldn't work. There is, however, a known bug that will cause a NullReferenceException to be thrown if no Width/Height is specified for the document:

<svg> instead of <svg width="800" height="600">

The library isn't able to calculate these yet, but hopefully this issue will be fixed in the next release.

If setting the width/height doesn't work (or if you're already setting them :-) ) raise a work item or send me mail with the Stack Trace and pie.svg if possible.

Let me know how you go!

Cheers,
Dave
Mar 31, 2010 at 9:55 AM

Hi

I have a problem with this code. Why?

 

Dim sd As SvgDocument = New SvgDocument()
        sd = SvgDocument.Open(Server.MapPath("/images/prova.svg"))
        sd.Draw().Save(Server.MapPath("/images/prova.png"), ImageFormat.Jpeg)

Dim sd As SvgDocument = New SvgDocument()

 sd = SvgDocument.Open(Server.MapPath("/images/prova.svg"))

 sd.Draw().Save(Server.MapPath("/images/prova.png"), ImageFormat.Jpeg)

System.IO.FileNotFoundException: The specified document cannot be found.

Any ideas?

Thanks.

Giuseppe

 

Coordinator
Apr 5, 2010 at 2:01 PM

Hmmm, going by the exception text it would appear that the file at "Server.MapPath("/images/prova.svg")" doesn't exist. Perhaps the map path is incorrect (e.g. is the slash at the beginning required... is the app running in the host root or does it have a virtual directory?)?

 

Apr 6, 2010 at 11:16 AM

Hi davescriven,

The application runs in the host. I also tried to specify the file with its absolute path.  > SvgDocument.Open("D:\Documents\Web\Image\prova.svg") 

 Nothing. This is the file I want to open:

<svg width="800" height="600">

  <path stroke-width="2" id="svg_102" d="m9.875,23c-2,-4.25 -1.6875,-7.375 1.6875,-10.5c3.375,-3.125 7.5625,-2.75 11.0625,2" stroke="#8dd35f" fill="none"/>

  <line fill="none" stroke="#606060" id="svg_109" y2="4" x2="19" y1="19" x1="4"/>

  <circle stroke="#0000ff" fill="#00ffff" id="svg_111" r="2.17578" cy="11.5" cx="11.5"/>

  <circle stroke-width="0.5" id="svg_121" stroke="#0000ff" fill="#00ffff" r="2.26172" cy="4" cx="19"/>

  <circle id="svg_123" stroke-width="0.5" stroke="#0000ff" fill="#00ffff" r="2.26172" cy="19" cx="4"/>

</svg>

 

Can you help me?

Coordinator
Apr 6, 2010 at 2:40 PM
Edited Apr 6, 2010 at 2:43 PM

I can get the above SVG to render in a very similar way to Firefox*. I did have to change one thing though. The root element must have a version and namespace:

 

<?xml version="1.0" encoding="utf-8" ?> 
<svg width="800" height="600"  xmlns="http://www.w3.org/2000/svg" version="1.1">
  <path stroke-width="2" id="svg_102" d="m9.875,23c-2,-4.25 -1.6875,-7.375 1.6875,-10.5c3.375,-3.125 7.5625,-2.75 11.0625,2" stroke="#8dd35f" fill="none"/>
  <line fill="none" stroke="#606060" id="svg_109" y2="4" x2="19" y1="19" x1="4"/>
  <circle stroke="#0000ff" fill="#00ffff" id="svg_111" r="2.17578" cy="11.5" cx="11.5"/>
  <circle stroke-width="0.5" id="svg_121" stroke="#0000ff" fill="#00ffff" r="2.26172" cy="4" cx="19"/>
  <circle id="svg_123" stroke-width="0.5" stroke="#0000ff" fill="#00ffff" r="2.26172" cy="19" cx="4"/>
</svg>

 

The above SVG renders the following image:

Let me know how you go.

Cheers,
Scriv

* - The stroke size of 0.5 appears to be rounded up to 1 in this SVG library. It makes some sense (how can it render half a pixel?) so I think Firefox/Inkscape etc have algorithims for helping with this. Changing the opacity tends to present *similar* results.

Apr 6, 2010 at 3:17 PM

The problem is that the server can not find the file!

Coordinator
Apr 7, 2010 at 12:35 AM

I can't really help with that issue, havana7. As I've shown I'm able to save the file and render it using the same APIs. It could be a security related issue if you're running in IIS; i.e. you might have to grant ASP.NET access to the folder that contains the file. I'd like to help but it's really just down to server setup.