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

850 views Asked by At

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!

1

There are 1 answers

0
Jakob Ofner On BEST ANSWER

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())