Embed SVG into PDF programmatically in .NET C#

12,346

Solution 1

PrinceXML does a very good job of handling SVG, however, it is not completely free, meaning that the free version puts a small logo on the output PDF. You can find out more here: http://www.princexml.com/doc/7.0/svg/

PDFJet will allow you to create lines, circles, polygons, and other primitive drawing tools. You could create a class to parse your SVG and then draw the appropriate circles, arcs, lines, etc and use PDFJet to make the PDF. PDFJet can be downloaded here: http://pdfjet.com/os/edition.html

Other then that, I don't think there are many other options for what you are looking to do.

Solution 2

PDFKit.NET3 can insert the SVG document into PDF, while preserving vectors.

Solution 3

webSupergoo ABCpdf is also a good commercial option, a bit less pricey (ABCpdf Std costs $329, and ABCpdf Pro cost $479 if you want rendering or x64 support). Version 7 did a terrible job when handling SVG files (it could only load a small subset, often with issues), but I understand (haven't test it first hand) that version 8 (and now 9) greatly improved its SVG support by switching to the Gecko engine.

Share:
12,346
Dragouf
Author by

Dragouf

I'm french so sorry for my english ;)

Updated on June 13, 2022

Comments

  • Dragouf
    Dragouf about 2 years

    Does anyone know how to create a pdf with C# and add a SVG document inside of this PDF ?

    itextsharp can't do it.

    I convert SVG into image thanks to this library (http://svg.codeplex.com/) but I need to keep vectorial graphic because image is pixelised.

    Anyone know a library to do it ?

    Thanks,

    • Armance
      Armance over 12 years
      is it possible with itextsharp. MyImageStream = new MemoryStream(); myChart.SaveImage(MyImageStream); my chart would be the svg chart object
    • Dragouf
      Dragouf over 12 years
      I changed the way to do this. I convert svg in emf and generate a docx. But so with this solution when you zoom on the image it's not pixelize? If it's not pixelize propose it as solution. But I can't test anymore cz I changed all my code.
  • Dragouf
    Dragouf almost 13 years
    The second solution is very complicate. The first one is nice but I can't accept a logo.
  • Icemanind
    Icemanind almost 13 years
    @Dragouf - Actually, there is a SVG library here: An SVG Framework in C# and an SVG-GDI+ bridge You could use this library to parse the SVG, then use PDFJet or even iTextSharp to draw the poly, line and arc primitives.
  • Dragouf
    Dragouf almost 13 years
    It seems its a long coding and I don't have enought time. But it seems pdf can embed svg xobject if I well understand. For me moment I use to convert svg with inkscape command line and then merge pdf with itextsharp. But I can't position the resulting object correctly on the page... :s
  • Azimuth
    Azimuth over 6 years
    Unfortunately it has terrible support for Azure... They state on their website that one has to set up a virtual machine. I'm trying to migrate a solution using ABCpdf to Azure Web App and this library is currently is the only obstacle...