Insert SVGs in table cells: exception

Hi,
the following code leads to exception. IMPORTANT: with less inserts work!

            // Instantiate Document Object
            var doc = new Pdf.Document();

            // Add a page to pages collection of document
            var page = doc.Pages.Add();

            var table = new Pdf.Table();
            table.ColumnWidths = Width + " " + Width;
            // Set the table border color as LightGray
            table.Border = new Pdf.BorderInfo(Pdf.BorderSide.All, .5f, Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
            // Set the border for table cells
            table.DefaultCellBorder = new Pdf.BorderInfo(Pdf.BorderSide.All, .5f, Pdf.Color.FromRgb(System.Drawing.Color.LightGray));

            page.Paragraphs.Add(table);

            for (var index = 0; index<10; index++)
            {
                var row = table.Rows.Add();

                var cell = row.Cells.Add();

                // Create an image object
                var image1 = new Aspose.Pdf.Image();
                image1.File = "sample_car.svg";
                image1.FileType = Aspose.Pdf.ImageFileType.Svg;

                // Aspose.Pdf measuring unit is point, 1 inch= 72 point= 2.54 cm
                image1.FixWidth = 283.4645669;
                image1.FixHeight = 283.4645669;

                // Add the image into paragraphs collection of the section
                cell.Paragraphs.Add(image1);
            }

            // Set the image file stream
            // Save resultant PDF file
            doc.Save("DocumentWithCar.pdf");

I get the followinf exception: “Cannot open an image. The image file format may be not supported at the moment.”

@david.csillik.messerli

We have tested the scenario in our environment with one of our sample SVG image and Aspose.PDF for .NET 20.10. We were not able to reproduce the exception at our side. Would you kindly share your sample SVG in .zip format along with the value of “Width” variable in your code above? We will again test the scenario in our environment and address it accordingly.

Hi Ali,
here is my sample SVG. I have tested it under Windows.
sample_car.zip (106.1 KB)

Maybe it helps:AsposeException.PNG (12.9 KB)

@david.csillik.messerli

We have been able to reproduce the issue in our environment while testing the scenario with Aspose.PDF for .NET 20.10. Therefore, have logged an issue as PDFNET-48943 in our issue management system for the sake of correction. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

Hi. I’m having the same problem with Aspose.PDF for .Net 21.2.

Here’s a very simple code snippet that I can confirm, works perfectly fine with PNG images.

var image = new Image
{
    File = iconFilePath,
    FileType = ImageFileType.Svg,
    FixWidth = 304,
    FixHeight = 80,
    HorizontalAlignment = HorizontalAlignment.Center
};

This is one of the SVG images I’m trying to use:
electric-mast.svg.zip (617 Bytes)

Thanks for your help!

@frostmonkey

We have logged another ticket i.e. PDFNET-49478 in our issue tracking system for your file. We will further look into its details and keep you posted with its rectification status. Please be patient and spare us some time.

We are sorry for the inconvenience.

1 Like

Thank you. For the time being, I’ve exported the SVG files to the PNG format, and it works fine. It’s just an extra step that would be great to remove from our deployment process.

Thanks for the quick response.

1 Like

@frostmonkey

Thanks for writing to us.

We have logged these details along with the ticket as well and will surely consider them during the investigation.

1 Like