When importing a SVG as an Image, its inserted into the PDF as a raster image with bad compression as well as replacing transparency with a white background. How do I get it to insert it as a vector image drawing?
double originalWidth = 0, originalHeight = 0, ratioX = 1, ratioY = 1, ratio = 1;
//Using SVG Nuget Package to accurately read SVG dimensions
//and to change them
//https: //github.com/vvvv/SVG
SvgDocument svgDocument = Svg.SvgDocument.Open(imagePath);
originalWidth = svgDocument.Width;
originalHeight = svgDocument.Height;
//aspect ratios
ratioX = maxWidth / originalWidth ?? 1;
ratioY = maxHeight / originalHeight ?? 1;
//smallest ratio wins
ratio = Math.Min(ratioX, ratioY);
float newWidth = (float)Math.Ceiling(originalWidth * ratio);
float newHeight = (float)Math.Ceiling(originalHeight * ratio);
svgDocument.Width = new Svg.SvgUnit((float)newWidth);
svgDocument.Height = new Svg.SvgUnit((float)newHeight);
var svg = new Image
{
FileType = ImageFileType.Svg,
IsInLineParagraph = true,
// new height and width
FixWidth = newWidth,
FixHeight = newHeight,
IsApplyResolution = true
};
var stream = new MemoryStream();
svgDocument.Write(stream);
svg.ImageStream = stream;
return svg;
I would have uploaded the SVG but your forum blocks that filetype.
We have tested the scenario in our environment and were able to replicate the issue. We have logged it as PDFNET-45879 in our issue tracking system for the sake of detailed investigation. We will further look into details of the issue and keep you posted with the status of its correction. Please be patient and spare us little time.
We really apologize for the inconvenience. The earlier logged ticket could not get resolved due to which you are experiencing same issue in the 21.9 version of the API. We have logged another ticket as PDFNET-50758 in our issue management system for the recent case. We will surely work on resolving the issue and let you know as soon as it is fixed. Please give us some time.
We again apologize for the delay and the inconvenience.
We are afraid that the ticket(s) could not get resolved due to other pending issues in the queue. However, your concerns have been recorded and we will surely inform you once we make some progress in this regard. We apologize for the inconvenience.