Esempio n. 1
0
        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);
        }
Esempio n. 3
0
 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");
 }
Esempio n. 4
0
        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 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);
        }