Open
Description
let me show these problems by code and image:
SVG File
<svg width="100mm" height="35mm" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 175">
<rect x="0" y="0" width="500" height="175" fill="white" stroke="#000000" stroke-width="2" />
<g fill="#000000">
<text x="250" y="26" font-size="24" font-weight="500" dominant-baseline="middle" text-anchor="middle">Meterial Pakage Label</text>
<text x="19" y="44" dy="16" font-size="16">Meterial: 101004117</text>
<text x="290" y="44" dy="16" font-size="16">Quantity: 30.000 PC</text>
<text x="19" y="72" dy="16" font-size="16">Lot: 2402050001</text>
<text x="290" y="72" dy="16" font-size="16">Order: 490130186</text>
<text x="19" y="100" dy="16" font-size="16">Name: XXXXXXXXXXXXXXXXXXXXXXX</text>
</g>
</svg>
C# Code
SvgDocument svgDocument = SvgDocument.Open(this.SVGPath).FixImageSize();
svgDocument.ShapeRendering = SvgShapeRendering.Auto;
svgDocument.Ppi = 150;
//Draw on A4 paper
Bitmap bmp = new Bitmap(4960, 7015);
bmp.SetResolution(600, 600);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.White);
svgDocument.Draw(g);
g.Flush();
bmp.Save("D:\\1.bmp");
First Problem :Text layout Error
Second Problem :Image size(maybe it's not a bug)
When we setsolution for Bitmap object, the meaning is keeping physical size (cm / mm / inch) . Graphics should auto-resize drawing objects to fit the resolution. but SvgDocument.Ppi changes the physical size. In other words, SvgDocument convert between physical-unit and pixel always on 96 PPI.
Metadata
Metadata
Assignees
Labels
No labels