如何使用PdfSharp将.SVG写入pdf

MyD*_*ons 1 c# svg pdfsharp

我正在使用PdfSharp并保存.png文件.它工作正常.现在我需要保存SVG图像,我收到一个错误

System.OutOfMemoryException: Out of memory.
Run Code Online (Sandbox Code Playgroud)

代码是

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
Run Code Online (Sandbox Code Playgroud)

如果我将上面的.svg更改为.png它可以正常工作(因为我有两个,同名的.png和.svg文件)

如何使用PDF Sharp将SVG图像保存为PDF?

Je *_*not 7

PDFsharp支持像PNG和JPEG这样的光栅图像.尚不支持SVG等矢量图像.这不是错误,这是一个实现限制.

XImage.FromFile将图像传递给GDI +或WPF(取决于您正在使用的构建),并期望得到一个光栅图像作为回报.我不知道GDI +或WPF返回SVG图像是什么.

如果您找到使用Graphics对象绘制SVG图像的源代码,那么您可以轻松地将其用于PDFsharp的XGraphics对象.

或者尝试找到将SVG转换为光栅图像的库.