wkhtmltopdf missing SVG paths (Rendering)

后端 未结 2 2189
面向向阳花
面向向阳花 2021-02-19 02:41

I\'m using a image inside the HMTL code like here below:

2条回答
  •  滥情空心
    2021-02-19 03:18

    A workaround is to convert the .SVG files to .PNG files before converting to .PDF. The .SVG code can be extracted via AgilityPack or read the files as a string. Then use the Svg library to convert to .PNG as follows:

    var svg = SvgDocument.FromSvg(svgXmlAsString);
    var bitmap = svg.Draw();
    var codec = "image/png".ParseImageCodecInfo();
    // intermediaryStream required due to image.Save attempting read access
    using (var intermediaryStream = new MemoryStream())
    {
        bitmap.Save(intermediaryStream, codec);
        intermediaryStream.Position = 0;
        await intermediaryStream.CopyToAsync(responseStream);
        await intermediaryStream.FlushAsync();
        await responseStream.FlushAsync();
    }
    

提交回复
热议问题