I'm using PdfSharp and saving .png files. It works fine. Now I need to save SVG images and I'm getting an error
System.OutOfMemoryException: Out of memory.
The code is
var path = @"D:\Projects\ProjectName\Content\Images\Instruments";
path += Path.GetFileName(instrument.Src); //instrument.src is a valid name and the path is a valid path on the local machine, which is where I'm testing
if (!File.Exists(path))
return; //never hit as the path is correct
var img = XImage.FromFile(path); //out of memory
//more code
If I change the above from .svg to .png it works fine (since I have both, a .png and .svg file with the same name)
How can I save the SVG image to PDF using PDF Sharp?
PDFsharp supports raster images like PNG and JPEG. Vector images like SVG are not yet supported. This is not a bug, this is an implementation restriction. Pages from PDF files can be used like images and allow using vector images with PDFsharp.
XImage.FromFile passes the image to either GDI+ or WPF (depending on the build you are using) and expects to get a raster image in return. I do not know what GDI+ or WPF return for SVG images.
If you find source code that draws SVG images using a Graphics object then you can easily adopt that for PDFsharp's XGraphics object.
Or try to find a library that converts SVG to raster images or PDF files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With