SVG not displayed in pdf

Hi,

when I add an SVG from file to a .docx and then save it as PDF I get a frame showing “The picture can’t be displayed”, see screenshot below. This error happens when using the example code locally. I tried it on two different machines, with the same result.
Installed version is GemBox.Document 2025.5.105

Cheers

Hi,

If you’re targeting “net8.0”, can you please try again by targeting “net8.0-windows”.
In other words, instead of this:

<TargetFramework>net8.0</TargetFramework>

Try this:

<TargetFramework>net8.0-windows</TargetFramework>

The problem occurs because currently, GDI+ is required for exporting SVG, EMF, and WMF images. However, note that in the future we plan to remove this dependency, and we plan to add direct support for vector image formats in the output PDF.

Regards,
Mario

Thanks, that does solve the problem for local development. Yet in production, our systems are running in Linux containers. How would I solve the problem for Linux?

Unfortunately, this is currently not solvable for Linux. SVG, EMF, and WMF exporting is currently a Windows-only feature.

Oh. That is quite problematic for us. We did not see that coming since it is not clearly mentioned in the linux support page.

You wrote

have you already scheduled the feature with a specific date?

Cross-platform support for exporting SVG, EMF, and WMF images should be available before the end of this summer.

Thanks for the fast response. As a reminder for myself and should someone else have that problem, a possible fallback could be to convert the SVG to TIFF and use those instead.

dotnet add package Svg.Skia
dotnet add package SkiaSharp
dotnet add package BitMiracle.LibTiff.NET
dotnet add package SkiaSharp.NativeAssets.Linux
For local development on Windows or additional Windows deployments:
dotnet add package SkiaSharp.NativeAssets.Windows

var svg = new SKSvg();
svg.Load("input.svg");
var picture = svg.Picture;
var originalBounds = picture.CullRect;

// Scale factor
float scaleFactor = 15.0f;

// Scale dimensions
int width = (int)(originalBounds.Width * scaleFactor);
int height = (int)(originalBounds.Height * scaleFactor);

// Create scaled bitmap
using var bitmap = new SKBitmap(width, height, SKColorType.Bgra8888, SKAlphaType.Premul);
using var canvas = new SKCanvas(bitmap);
canvas.Clear(SKColors.White);

// Scale the drawing to match new bitmap size
canvas.Scale(scaleFactor);

// Draw the picture (internally still using original SVG coordinates)
canvas.DrawPicture(picture);
canvas.Flush();

// Create TIFF
using var tif = Tiff.Open("output.tiff", "w");

tif.SetField(TiffTag.IMAGEWIDTH, width);
tif.SetField(TiffTag.IMAGELENGTH, height);
tif.SetField(TiffTag.SAMPLESPERPIXEL, 4); // BGRA
tif.SetField(TiffTag.BITSPERSAMPLE, 8);
tif.SetField(TiffTag.ORIENTATION, Orientation.TOPLEFT);
tif.SetField(TiffTag.ROWSPERSTRIP, height);
tif.SetField(TiffTag.XRESOLUTION, 96.0 * scaleFactor);  // logical DPI
tif.SetField(TiffTag.YRESOLUTION, 96.0 * scaleFactor);
tif.SetField(TiffTag.RESOLUTIONUNIT, ResUnit.INCH);
tif.SetField(TiffTag.PHOTOMETRIC, Photometric.RGB);
tif.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
tif.SetField(TiffTag.COMPRESSION, Compression.LZW);

// Write bitmap pixel rows to TIFF
var pixels = bitmap.Bytes;
int stride = width * 4;

for (int i = 0; i < height; i++)
{
    int offset = i * stride;
    var row = new byte[stride];
    Buffer.BlockCopy(pixels, offset, row, 0, stride);
    tif.WriteScanline(row, i);
}

tif.WriteDirectory();
1 Like