I am using SVG-Net for creating PNG,JPG files from SVG.
Problem I am facing is, fonts are not rendering in PNG,JPG from SVG, although when I view my SVG, font shows.
Following is my code:
var svgContent = svgDocument.ToString();
var mySvg = SvgDocument.FromSvg<SvgDocument>(svgContent);
mySvg.Height = new SvgUnit(SvgUnitType.Pixel, pixelHeight);
mySvg.Width = new SvgUnit(SvgUnitType.Pixel, pixelWidth);
mySvg.ViewBox = new SvgViewBox(0, 0, viewBoxWidth, viewBoxHeight);
Bitmap bmpSquare = mySvg.Draw(pixelWidth, pixelHeight);
bmpSquare.Save(FilePathJPG, jgpEncoder,myEncoderParameters);
bmpSquare.Save(FilePathPNG, pngEncoder,myEncoderParameters);
I have ttf files, it works on my local when I install the fonts on my machine locally in C:/Windows/Fonts.
But same is not feasible when my Azure Function App is deployed.
Can there be a way to install font on PaaS on Azure?
For SVG in added font-face and adding ttf file in base64 format.
or is there a way I can render the fonts in SVG-Net library I am using.
Following is the code I used in SVG:
<defs>
<style>
@font-face {
font-family:Segoe Pro Bold;
src: url("data:font/truetype;charset=utf-8;base64, bas64 conversion of my font TTF file") format('truetype');
}
</style>
</defs>
Using the above code shows the font on my SVG, but it renders default font when I convert Bitmap & save to PNG & JPG.
I am so close to my deadlines, I have completed the hardest of things but stuck with this critical issue.
Thanks in advance.
2
Answers
Issue resolved using the SVG.NET Library I was using for SVG to PNG,JPG conversion using the SvgFontManager.
Embedding fonts is not supported by svg-net, and as far as I know, svg-net relies entirely on OS-based font resolving. However, you could utilize Azure VMs or container-based Azure App Service Web Apps to install custom fonts. Additionally, there is a preview of Azure Container Apps hosting of Azure Functions.
For a container based function setup the docker file should look like this example
The sample svg renderd with svg-net in the azure function changes from to after the lines that install the font got added.
Used example svg: