Search code examples
c#abcpdfabcpdf9

How do I convert an SVG to PDF in C#?


How can I set a cookie at ABCpdf12 in this code?

string url = "";

Doc theDoc = new Doc();
theDoc.Read(url);
theDoc.Save("document.pdf");
theDoc.Clear();

Big thanks!


Solution

  • I've already solved the problem. I downloaded the svg with selenium and used iText7 to generate the PDF-file.

    I used itext7, which I've installed as NuGet-packet.

    using iText;
    using iText.Svg.Converter;
    

    and here the code:

    FileStream svgPath = File.Open("input.svg", FileMode.Open);
    FileStream pdfPath = File.Create("output.pdf");
    SvgConverter.CreatePdf(svgPath, pdfPath);
    

    To avoid errors, you should set the current location equal to the location of the svg file. (Directory.SetCurrentDirectory())