protected void buttonConvertToSvg_Click(object sender, EventArgs e) { // create the HTML to SVG converter HtmlToSvg htmlToSvgConverter = new HtmlToSvg(); // set a demo serial number htmlToSvgConverter.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ=="; // set browser width htmlToSvgConverter.BrowserWidth = int.Parse(textBoxBrowserWidth.Text); // set browser height if specified, otherwise use the default if (textBoxBrowserHeight.Text.Length > 0) { htmlToSvgConverter.BrowserHeight = int.Parse(textBoxBrowserHeight.Text); } // set HTML Load timeout htmlToSvgConverter.HtmlLoadedTimeout = int.Parse(textBoxLoadHtmlTimeout.Text); // set triggering mode; for WaitTime mode set the wait time before convert switch (dropDownListTriggeringMode.SelectedValue) { case "Auto": htmlToSvgConverter.TriggerMode = ConversionTriggerMode.Auto; break; case "WaitTime": htmlToSvgConverter.TriggerMode = ConversionTriggerMode.WaitTime; htmlToSvgConverter.WaitBeforeConvert = int.Parse(textBoxWaitTime.Text); break; case "Manual": htmlToSvgConverter.TriggerMode = ConversionTriggerMode.Manual; break; default: htmlToSvgConverter.TriggerMode = ConversionTriggerMode.Auto; break; } // convert to SVG string svgFileName = "HtmlToSvg.svg"; byte[] svgBuffer = null; if (radioButtonConvertUrl.Checked) { // convert URL string url = textBoxUrl.Text; svgBuffer = htmlToSvgConverter.ConvertUrlToMemory(url); } else { // convert HTML code string htmlCode = textBoxHtmlCode.Text; string baseUrl = textBoxBaseUrl.Text; svgBuffer = htmlToSvgConverter.ConvertHtmlToMemory(htmlCode, baseUrl); } // inform the browser about the data format HttpContext.Current.Response.AddHeader("Content-Type", "image/svg+xml"); // let the browser know how to open the SVG and the SVG file name HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}; size={1}", svgFileName, svgBuffer.Length.ToString())); // write the SVG buffer to HTTP response HttpContext.Current.Response.BinaryWrite(svgBuffer); // call End() method of HTTP response to stop ASP.NET page processing HttpContext.Current.Response.End(); }
public ActionResult ConvertToSvg(FormCollection collection) { // create the HTML to SVG converter HtmlToSvg htmlToSvgConverter = new HtmlToSvg(); // set a demo serial number htmlToSvgConverter.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ=="; // set browser width htmlToSvgConverter.BrowserWidth = int.Parse(collection["textBoxBrowserWidth"]); // set browser height if specified, otherwise use the default if (collection["textBoxBrowserHeight"].Length > 0) { htmlToSvgConverter.BrowserHeight = int.Parse(collection["textBoxBrowserHeight"]); } // set HTML Load timeout htmlToSvgConverter.HtmlLoadedTimeout = int.Parse(collection["textBoxLoadHtmlTimeout"]); // set triggering mode; for WaitTime mode set the wait time before convert switch (collection["dropDownListTriggeringMode"]) { case "Auto": htmlToSvgConverter.TriggerMode = ConversionTriggerMode.Auto; break; case "WaitTime": htmlToSvgConverter.TriggerMode = ConversionTriggerMode.WaitTime; htmlToSvgConverter.WaitBeforeConvert = int.Parse(collection["textBoxWaitTime"]); break; case "Manual": htmlToSvgConverter.TriggerMode = ConversionTriggerMode.Manual; break; default: htmlToSvgConverter.TriggerMode = ConversionTriggerMode.Auto; break; } // convert to SVG string svgFileName = "HtmlToSvg.svg"; byte[] svgBuffer = null; if (collection["UrlOrHtmlCode"] == "radioButtonConvertUrl") { // convert URL string url = collection["textBoxUrl"]; svgBuffer = htmlToSvgConverter.ConvertUrlToMemory(url); } else { // convert HTML code string htmlCode = collection["textBoxHtmlCode"]; string baseUrl = collection["textBoxBaseUrl"]; svgBuffer = htmlToSvgConverter.ConvertHtmlToMemory(htmlCode, baseUrl); } FileResult fileResult = new FileContentResult(svgBuffer, "image/svg+xml"); fileResult.FileDownloadName = svgFileName; return(fileResult); }