Exemplo n.º 1
0
        public async Task <object> ImageFile(string url = "http://news.baidu.com")
        {
            var image = new UrlAsImage(url);
            var path  = Path.Combine("wwwroot/files/image", DateTime.Now.ToString("yyyyMMddhhmmss") + ".png");

            image.SaveOnServerPath = path;
            await image.BuildFile(url);

            return(new { FileName = path });
        }
Exemplo n.º 2
0
        public IActionResult Image(string url = "http://news.baidu.com")
        {
            // way 1:
            //ViewData["Message"] = "Your application description page.";
            //var model = new TestModel { Name = "Giorgio" };
            //var image= new ViewAsImage("About",model);
            //image.PageWidth = 800;
            //image.PageHeight = 600;
            //return image;

            //way 2:
            var image = new UrlAsImage(url);

            image.SaveOnServerPath = Path.Combine("wwwroot/files/image", DateTime.Now.ToString("yyyyMMddhhmmss") + ".png");
            return(image);
        }
Exemplo n.º 3
0
        public void Can_build_the_image_binary()
        {
            var localPath         = Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory);
            var solutionDir       = localPath.Parent.Parent.Parent.FullName;
            var wkhtmltoimagePath = Path.Combine(solutionDir, "Rotativa", "Rotativa");
            var actionResult      = new UrlAsImage("https://github.com/webgio/Rotativa")
            {
                WkhtmlPath = wkhtmltoimagePath
            };
            var builder    = new TestControllerBuilder();
            var controller = new HomeController();

            builder.InitializeController(controller);
            var imageBinary = actionResult.BuildFile(controller.ControllerContext);

            var image = Image.FromStream(new MemoryStream(imageBinary));

            image.Should().Not.Be.Null();
            image.RawFormat.Should().Be.EqualTo(ImageFormat.Jpeg);
        }