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.

Edit: GemBox does not support an alpha channel in TIFF, removed alpha channel

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, 3); // RGB, SAMPLESPERPIXEL 4 = RGBA is not supported by GemBox 
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;

// SkiaSharp renders into a BGRA bitmap (Blue, Green, Red, Alpha — 4 bytes per pixel).
// But we are configuring the TIFF writer for RGB output (3 bytes per pixel, no alpha).
// => If we write the raw BGRA bytes directly into the TIFF as-is, the image will be misinterpreted,
//    leading to distorted or overly colorful output.
// => Therefore, we must strip out the 4th channel (Alpha) and reformat the pixel data to RGB.

// Iterate over each row of the bitmap image
for (int i = 0; i < height; i++)
{
    // Compute the byte offset to the start of row i in the original pixel buffer.
    // 'stride' is width * 4 since each pixel in the original bitmap has 4 bytes (BGRA).
    int offset = i * stride;

    // Prepare a new buffer for this scanline, using only 3 bytes per pixel (R, G, B)
    byte[] row = new byte[width * 3];

    // Convert each pixel from BGRA → RGB by skipping the alpha channel
    for (int x = 0; x < width; x++)
    {
        int src = offset + x * 4;  // Source pixel in BGRA format
        int dst = x * 3;           // Destination offset in RGB row

        // Copy the Blue, Green, and Red bytes from the original BGRA buffer
        // Skip the 4th byte (Alpha) to avoid writing it into the TIFF
        row[dst + 0] = pixels[src + 0]; // Blue
        row[dst + 1] = pixels[src + 1]; // Green
        row[dst + 2] = pixels[src + 2]; // Red
    }

    // Write the converted RGB scanline to the TIFF image
    tif.WriteScanline(row, i);
}

tif.WriteDirectory();