Search code examples
c#printinggdi+system.drawingprintdocument

Printing SVG-PictureFiles in C# PrintDocument GDI+


I coded a tool which prints small labels. Here´s my problem:

Every printed text on the label looks fine with e.Graphics.DrawString(...) -

Pictures printed with e.Graphics.DrawImage(...) look bad. Small parts like a Copyright-Sign is not readable.

DPI is set to 300 (maximum of printer).

I got those pictures in Vector/SVG-Format from Corel Draw - if I print the Corel Draw File it looks great!

How can I print SVG-Files or similar with C# (.NET 3.5 or 4.0)?

Greetings


Solution

  • I have used SVG# before and it worked very well. The project is old, so it might need minor tweaking before it compiles in your .net 3.5/4.0 projects.

    Once you get it compile, you may then try to the following snippet

    //Create a window that matches the desired output bitmap
    SvgWindow window = new SvgWindow(width, height);
    window.Src = svgSource;
    
    //Create a GDI renderer for SVG, and use white background
    GdiRenderer gdirender = new GdiRenderer(window, Color.White);
    Bitmap bitmap = gdirender.Render();
    

    It should generate a bitmap object that you may use to encode for your printing needs.