3

I would like to convert Svg stream to Pdf using ABCPdf in C#. The stream I receive contains the XML of the Svg. I am using Doc.AddImageHtml method provided by ABCPdf. Since I am getting only XML from the stream, I am prefixing and suffixing the html and body tags to it to make it a HTML. I am using the following Code for that :

Doc abcPdfDoc = new Doc();                                
XmlDocument xDocument = new XmlDocument();
xDocument.Load(stream);
abcPdfDoc.AddImageHtml("<html><body>" + xDocument.InnerXml + "</html></body>");
abcPdfDoc.Save(@"MyPdf.pdf");
abcPdfDoc.Clear();   

The issue is that the tables in my SVG are not retained. The output in my PDF a running text without tables.(Rect to be specific)

Any pointers on what can be done to retain the format or a better way to achieve the same using ABCPdf?

1 Answer 1

2

You don't need to use AddImageHtml. Assuming you are using fairly standard SVG based around the SVG Tiny spec, you can just Doc.Read the SVG straight in. This is fast, simple and efficient and it works well for most SVG documents.

If your SVG is more complex then you may wish to use the Gecko engine. To do this you can use AddImageHtml with your SVG setting the Doc.HtmlOptions.Engine property to EngineType.Gecko. The Gecko engine involves a greater overhead but provides full featured coverage of the SVG specification.

2
  • Thanks for the reply. I tried using Doc.Read by passing the Stream but it says the format is not recognized. If I pass SVG file from disk to Doc.Read, its successful. With a stream, it does not work for me. Also as I mentioned, the stream I receive contains the XML of the Svg. I will try setting the EngineType and see if it works.
    – Neelima
    Commented May 20, 2015 at 6:26
  • It worked when I used the Gecko Engine. Thanks a lot!!
    – Neelima
    Commented May 20, 2015 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.