public Byte[] ExportDrawing(string html) { var htmlToImageConv = new NReco.ImageGenerator.HtmlToImageConverter(); var jpegBytes = htmlToImageConv.GenerateImage(html, ImageFormat.Png); return(jpegBytes); }
private void OnTakeSnapshot(TakeSnapshot msg) { string htmlCode; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_uriAddress); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader sr = new StreamReader(response.GetResponseStream()); htmlCode = sr.ReadToEnd(); string fileName = Path.Combine(_snapshotBasePath, msg.Id + "_" + DateTime.UtcNow.ToString("yyyyMMddHHmmss") + ".jpg"); var documentMsg = new TakeSnapshotCompleted(msg.Id, fileName); Sender.Tell(documentMsg); if (!Directory.Exists(_snapshotBasePath)) { Directory.CreateDirectory(_snapshotBasePath); } HtmlToImageConverter htmlToImageConv = new NReco.ImageGenerator.HtmlToImageConverter(); try { byte[] jpegBytes = htmlToImageConv.GenerateImage(htmlCode, ImageFormat.Jpeg); File.WriteAllBytes(fileName, jpegBytes); } catch (Exception exc) { throw new GenerateSnapshotException(fileName); } Context.Parent.Tell(documentMsg); }
public async Task Hello(string color = "red") { string css = "<style>\nh1\n{\ncolor: " + color + ";\n}\n</style>"; string html = $"<h1>Hello {Context.User.Username }!</h1>"; var converter = new NReco.ImageGenerator.HtmlToImageConverter { Width = 250, Height = 90 }; var jpgBytes = converter.GenerateImage(css + html, NReco.ImageGenerator.ImageFormat.Jpeg); await Context.Channel.SendFileAsync(new MemoryStream(jpgBytes), "hello.jpg"); }
public MemoryStream GetWikiImage(PoePage itemBox) { var result = GetWikiHtml(itemBox); var convert = new NReco.ImageGenerator.HtmlToImageConverter { Width = 348, CustomArgs = "--quality 85", Zoom = 2 }; var image = convert.GenerateImage(result, ImageFormat.Png); var stream = new MemoryStream(image) { Position = 0 }; return(stream); }
public string MailWritter(string MailTO, string MailCC, string MailSubject, string EScenario, string ReportLocation) { using (SmtpClient SmtpServer = new SmtpClient()) { System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Welcome@123"); SmtpServer.Port = 587; SmtpServer.Host = "smtp.rediffmailpro.com"; mail = new System.Net.Mail.MailMessage(); mail.From = new MailAddress("*****@*****.**"); foreach (var address in MailTO.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { mail.To.Add(address); } foreach (var address1 in MailCC.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { mail.CC.Add(address1); } mail.Subject = MailSubject; StreamReader reader = new StreamReader("\\\\192.169.1.55\\Automation reports\\SCUF\\Report Repository\\Templates\\HTML Template\\EmailReportTemplate.html"); string body1 = string.Empty; body1 = reader.ReadToEnd(); body1 = body1.Replace("{Application}", Report.ProjName); body1 = body1.Replace("{Url}", Report.LURL); body1 = body1.Replace("{g}", Report.g1.ToString()); body1 = body1.Replace("{Scenario}", EScenario); body1 = body1.Replace("{Table}", arr2[1].ToString()); body1 = body1.Replace("{Table1}", arr2[2].ToString()); body1 = body1.Replace("{Table2}", arr2[3].ToString()); body1 = body1.Replace("{Table3}", arr2[4].ToString()); string mailpage = folderpath + "\\Mail.html"; StreamWriter sw1 = new StreamWriter(mailpage); sw1.WriteLine(body1); sw1.Close(); string htmlfilepath = mailpage; var htmlToImageConv = new NReco.ImageGenerator.HtmlToImageConverter(); string imagefilepath = folderpath + "\\EMailReport.jpeg"; htmlToImageConv.GenerateImageFromFile(htmlfilepath, NReco.ImageGenerator.ImageFormat.Jpeg, imagefilepath); LinkedResource LinkedImage = new LinkedResource(imagefilepath); LinkedImage.ContentId = "MyPic"; LinkedImage.ContentType = new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Image.Jpeg); AlternateView htmlView = AlternateView.CreateAlternateViewFromString("<img src=cid:MyPic>", null, "text/html"); htmlView.LinkedResources.Add(LinkedImage); mail.AlternateViews.Add(htmlView); SmtpClient smtp = new SmtpClient("111.111.111.111", 25); System.Net.Mail.Attachment oAttch = new System.Net.Mail.Attachment(mplocation); System.Net.Mail.Attachment oAttch1 = new System.Net.Mail.Attachment(folderpath + "\\OverallStatus.html"); mail.Attachments.Add(oAttch); mail.Attachments.Add(oAttch1); SmtpServer.Send(mail); reader.Close(); return(body1); } }
public ActionResult PrintTicket(int codVenT) { Session["EntregaBusca"] = null; Session["imagen"] = null; /* if (generarBoleta(codVenT)) { //Se imprimio :) } */ List<Entrada> listaEntradas = new List<Entrada>(); CultureInfo culture = new CultureInfo("es-PE"); var lista = from obj in db.DetalleVenta where obj.codVen == codVenT select obj; foreach (var detalle in lista) { int? cant = detalle.cantEntradas; var axf = db.AsientosXFuncion.Where(c => c.codDetalleVenta == detalle.codDetalleVenta && c.codFuncion == detalle.codFuncion); if (axf != null && axf.Count() != 0) { foreach (var dato in axf) { Entrada ticket = new Entrada(); var fu = db.Funcion.Find(detalle.codFuncion); var evento = db.Eventos.Find(fu.codEvento); if (evento.idLocal.HasValue) { var local = db.Local.Find(evento.idLocal); ticket.Local = local.descripcion; ticket.Direccion = local.ubicacion; } else { ticket.Direccion = evento.direccion; } var pe = db.PrecioEvento.Find(detalle.codPrecE); var zona = db.ZonaEvento.Find(pe.codZonaEvento); ticket.Lugar = evento.Region.nombre; ticket.Evento = evento.nombre; ticket.Precio = pe.precio; ticket.Fecha = fu.fecha.Value.ToString("dddd d # MMMM # yyyy", culture).Replace("#", "de"); ticket.Zona = zona.nombre; ticket.Hora = fu.horaIni.Value.ToString("hh:mm tt", culture); var asiento = db.Asientos.Find(dato.codAsiento); ticket.Asiento = "Fil: " + asiento.fila + " Col: " + asiento.columna; ticket.Codigo = "" + evento.codigo + "" + fu.codFuncion + "" + codVenT + "" + cant; var funcion = db.VentasXFuncion.Where(c => c.codVen == codVenT && c.codFuncion == fu.codFuncion); if (funcion != null && funcion.Count() > 0) { funcion.First().hanEntregado = true; } listaEntradas.Add(ticket); } } else { for (int i = 0; i < cant; i++) { Entrada ticket = new Entrada(); var fu = db.Funcion.Find(detalle.codFuncion); var evento = db.Eventos.Find(fu.codEvento); if (evento.idLocal.HasValue) { var local = db.Local.Find(evento.idLocal); ticket.Local = local.descripcion; ticket.Direccion = local.ubicacion; } else { ticket.Direccion = evento.direccion; } var pe = db.PrecioEvento.Find(detalle.codPrecE); var zona = db.ZonaEvento.Find(pe.codZonaEvento); ticket.Lugar = evento.Region.nombre; ticket.Evento = evento.nombre; ticket.codEvento = evento.codigo; ticket.Precio = pe.precio; ticket.Fecha = fu.fecha.Value.ToString("dddd d # MMMM # yyyy", culture).Replace("#", "de") + " " + fu.horaIni.Value.ToString("hh:mm tt", culture); ticket.Zona = zona.nombre; ticket.Codigo = "" + evento.codigo + "" + fu.codFuncion + "" + codVenT + "" + cant; var funcion = db.VentasXFuncion.Where(c => c.codVen == codVenT && c.codFuncion == fu.codFuncion); if (funcion != null && funcion.Count() > 0) { funcion.First().hanEntregado = true; } listaEntradas.Add(ticket); } } } db.SaveChanges(); var data = listaEntradas.First(); var st = ""; this.ViewData.Model = data; string path = HttpContext.Server.MapPath("~/Images/imagen.png"); path = path.Replace('\\', '/'); Session["path"] = path; using (StringWriter stringWriter = new StringWriter()) { ViewEngineResult viewResult = ViewEngines.Engines.FindView(this.ControllerContext, "GeneraTicket", null); ViewContext viewContext = new ViewContext(this.ControllerContext, viewResult.View, this.ViewData, this.TempData, stringWriter); viewResult.View.Render(viewContext, stringWriter); st = stringWriter.GetStringBuilder().ToString(); } var converter = new NReco.ImageGenerator.HtmlToImageConverter(); converter.Width = 710; var jpegBytes = converter.GenerateImage(st, ImageFormat.Png); try { List<String> printers = new List<string>(); string name; for (int i = 0; PrinterSettings.InstalledPrinters.Count > i; i++) { name = PrinterSettings.InstalledPrinters[i]; printers.Add(name); } PrintDocument pd = new PrintDocument(); Stream stream = new MemoryStream(jpegBytes); string def = pd.PrinterSettings.PrinterName; pd.PrinterSettings.PrinterName = printers.Where(c => c.Contains("redireccionado")).First(); pd.PrintPage += (sender, args) => { Image i = Image.FromStream(stream); Rectangle m = new Rectangle(0, 0, 700, 250); args.Graphics.DrawImage(i, m); }; pd.Print(); } catch(Exception ex) { } Session["imagen"] = jpegBytes; return View(data); }