Thursday, 31 October 2013

Convert SVG to PNG using svg.dll

      <div id="divsvg">

       <svg width="350" height="300"><defs></defs> ................</svg>

        </div>

<script type="text/javascript">

        var svg = $('#divsvg').html();

        document.getElementById("<%= hfdata.ClientID %>").value = encodeURIComponent(svg);

</script>

Code behind:

            var svg = hfdata.Value;

            var urldec = System.Web.HttpUtility.UrlDecode(svg);

             var svgpath = Server.MapPath("~") + "temp\\" + sessionid + ".svg";

            File.WriteAllText(svgpath, urldec);

            var sampleDoc = SvgDocument.Open(svgpath);

            sampleDoc.Draw().Save(Server.MapPath("~") + "\\App_Data\\tempImages\\" + sessionid + ".png");

Generate Pdf Using HTML file and iTextSharp

string contents = File.ReadAllText(HttpContext.Current.Server.MapPath("user.htm"));

string receiptString = this.GetReceiptString(contents);

string PdfPathwithName = Server.MapPath("~") + "\\temp\\" + DateTime.Now.ToString("ddMMyyyyhhmmss") + ".pdf";

Document document = new Document(PageSize.B4);

PdfWriter writer = PdfWriter.GetInstance(

document,

new FileStream(PdfPathwithName, FileMode.Create));

PdfDestination pdfDest = new PdfDestination(PdfDestination.XYZ, 0, document.PageSize.Height, 1.00f);

document.Open();

PdfAction action = PdfAction.GotoLocalPage(1, pdfDest, writer);

writer.SetOpenAction(action);

XMLWorkerFontProvider fontProvider = new XMLWorkerFontProvider();

CssAppliers cssAppliers = new CssAppliersImpl(fontProvider);

HtmlPipelineContext htmlContext = new HtmlPipelineContext(cssAppliers);

htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());

ICSSResolver cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(true);

IPipeline pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, writer)));

XMLWorker worker = new XMLWorker(pipeline, true);

XMLParser p = new XMLParser(true, worker, Encoding.UTF8);

TextReader reader = new StringReader(receiptString);

p.Parse(reader);

p.Flush();

document.Close();

document.Dispose();

Convert SVG to PNG using svg.dll

      <div id="divsvg">        <svg width="350" height="300"><defs></defs> ............