I am developing in C# with the 4.0 .Net Framework. I am needing to take raw XML that a third-party sends us, apply a style sheet (also supplied by this third-party) to the XML, and then take the HTML that is generated from that, and save it as a PDF.
I am using XSLTransform to apply a style sheet to the XML, and get HTML generated. I have that working. However, I am struggling with how to convert that HTML to a PDF.
Any suggestions? Preferrable, there is already a solution for this by using the 4.0 .Net Framework; preferrable I will not have to install any new libraries.
If I can get the HTML to a System.Drawing.Image, I can then save that as a PDF. We have PDFSharp that I can use for manipulating PDF's.
I have seen a lot of posts on this topic, but most posts that I have found seem older, and require downloading or purchasing new libraries. I am hoping a more current solution exists.
Here is my code for applying the style sheet to the XML. I have the HTML available in my XMLWriter, or in my "outputString". (I am not convinced this is the best way to apply a style sheet to XML, so if there are any suggestions on better ways to do this, those are welcome).
string outputString = string.Empty;
XslCompiledTransform xslTransform = new XslCompiledTransform();
XsltSettings xsltSettings = new XsltSettings(true, true);
XmlUrlResolver resolver = new XmlUrlResolver();
xslTransform.Load("./ISOResultStyleSheetFiles/CS_XML_Output.xsl", xsltSettings, resolver);
using (StringReader sri = new StringReader(result.Result))
using (XmlReader xri = XmlReader.Create(sri))
using (StringWriter sw = new StringWriter())
using (XmlWriter xwo = XmlWriter.Create(sw, xslTransform.OutputSettings))
outputString = sw.ToString();