예제 #1
0
        public ActionResult Index(FormModel form)
        {
            GrabzItClient grabzItClient = GrabzItClient.Create(ConfigurationManager.AppSettings["ApplicationKey"], ConfigurationManager.AppSettings["ApplicationSecret"]);

            form.UseCallbackHandler = !HttpContext.Request.IsLocal;
            try
            {
                if (form.Format == "jpg")
                {
                    if (form.Convert == "html")
                    {
                        grabzItClient.HTMLToImage(form.HTML);
                    }
                    else
                    {
                        grabzItClient.URLToImage(form.URL);
                    }
                }
                else if (form.Format == "docx")
                {
                    if (form.Convert == "html")
                    {
                        grabzItClient.HTMLToDOCX(form.HTML);
                    }
                    else
                    {
                        grabzItClient.URLToDOCX(form.URL);
                    }
                }
                else if (form.Format == "gif")
                {
                    grabzItClient.URLToAnimation(form.URL);
                }
                else
                {
                    if (form.Convert == "html")
                    {
                        grabzItClient.HTMLToPDF(form.HTML);
                    }
                    else
                    {
                        grabzItClient.URLToPDF(form.URL);
                    }
                }
                if (form.UseCallbackHandler)
                {
                    grabzItClient.Save(HttpContext.Request.Url.Scheme + "://" + HttpContext.Request.Url.Authority + HttpContext.Request.ApplicationPath + "Home/Handler");
                }
                else
                {
                    grabzItClient.SaveTo(Server.MapPath("~/results/" + Guid.NewGuid().ToString() + "." + form.Format));
                }
                form.Message = "Processing...";
            }
            catch (Exception ex)
            {
                form.Error = ex.Message;
            }
            return(View(form));
        }
예제 #2
0
        //This method takes the users project link and gets s
        private byte[] GetBytesFromImage(string url)
        {
            GrabzItClient grabzIt = GrabzItClient.Create("OTc4YWU2YjFlMGQxNGI1YmEyNWJiYThjNTAyYWEzODc=", "P2w/Jz80FTMICj9DP2IQOyJ3dkdoPz8/Yj8/P1RQPz8=");

            ImageOptions m = new ImageOptions();

            m.CustomWaterMarkId = "";

            m.Quality = 100;

            m.BrowserHeight = 1280;

            m.BrowserWidth = 1024;

            grabzIt.URLToImage(url, m);

            byte[] bytes = grabzIt.SaveTo().Bytes;

            return(bytes);
        }
예제 #3
0
        public async Task CaptureScreenshotAsync(string routeId, LinkModel link)
        {
            try
            {
                bool enableScreenshots = bool.Parse(Environment.GetEnvironmentVariable("EnableScreenshots"));

                if (enableScreenshots)
                {
                    var           applicationKey    = Environment.GetEnvironmentVariable("GrabzitApplicationKey");
                    var           applicationSecret = Environment.GetEnvironmentVariable("GrabzitApplicationSecret");
                    GrabzItClient grabzIt           = new GrabzItClient(applicationKey, applicationSecret);

                    var imageOptions = new ImageOptions
                    {
                        Format = ImageFormat.jpg
                    };

                    grabzIt.URLToImage(link.Target, imageOptions);

                    var file = grabzIt.SaveTo();

                    var azManager = new AzureStorageManager(Environment.GetEnvironmentVariable("StorageConnectionString"));

                    var screenshotFileName = $"{routeId}-{Guid.NewGuid()}.jpg";

                    await azManager.StoreFile("screenshots", screenshotFileName, file.Bytes);

                    link.ScreenshotFileName = screenshotFileName;

                    _logger.LogInformation($"Saved Link Screenshot: {screenshotFileName}");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to process screenshot: {ex.Message}");

                throw ex;
            }
        }
예제 #4
0
파일: Program.cs 프로젝트: sarojdw/grabzit
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("Return Capture as PDF (P), DOCX (D), JPEG (J) or Animated GIF (G)? Enter P, J or G.");
                string formatType = Console.ReadLine();

                bool convertUrl = true;
                if (formatType != GIF)
                {
                    Console.WriteLine("Do you want to convert a URL (U) or to convert HTML (H)? Enter U or H.");
                    convertUrl = (Console.ReadLine() == "U");
                }

                if (convertUrl)
                {
                    Console.WriteLine("Please specify a URL to capture. For example http://www.google.com");
                }
                else
                {
                    Console.WriteLine("Please specify some HTML to convert.");
                }

                string inputData = Console.ReadLine();

                GrabzItClient grabzIt = GrabzItClient.Create(ConfigurationManager.AppSettings["ApplicationKey"],
                                                             ConfigurationManager.AppSettings["ApplicationSecret"]);

                try
                {
                    string format = ".jpg";
                    if (formatType == PDF)
                    {
                        format = ".pdf";
                    }
                    else if (formatType == DOCX)
                    {
                        format = ".docx";
                    }
                    else if (formatType == GIF)
                    {
                        format = ".gif";
                    }

                    string filename = Guid.NewGuid().ToString() + format;

                    if (formatType == PDF)
                    {
                        if (convertUrl)
                        {
                            grabzIt.URLToPDF(inputData);
                        }
                        else
                        {
                            grabzIt.HTMLToPDF(inputData);
                        }
                    }
                    else if (formatType == DOCX)
                    {
                        if (convertUrl)
                        {
                            grabzIt.URLToDOCX(inputData);
                        }
                        else
                        {
                            grabzIt.HTMLToDOCX(inputData);
                        }
                    }
                    else if (formatType == GIF)
                    {
                        grabzIt.URLToAnimation(inputData);
                    }
                    else
                    {
                        if (convertUrl)
                        {
                            grabzIt.URLToImage(inputData);
                        }
                        else
                        {
                            grabzIt.HTMLToImage(inputData);
                        }
                    }
                    if (grabzIt.SaveTo(filename))
                    {
                        if (formatType == GIF)
                        {
                            Console.WriteLine("Animated GIF has been saved to: " + filename);
                        }
                        else if (formatType == PDF)
                        {
                            Console.WriteLine("PDF has been saved to: " + filename);
                        }
                        else if (formatType == DOCX)
                        {
                            Console.WriteLine("DOCX has been saved to: " + filename);
                        }
                        else
                        {
                            Console.WriteLine("Image has been saved to: " + filename);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                Console.WriteLine("Do you wish to exit? (y/n)");
                string exit = Console.ReadKey().KeyChar.ToString();
                if (exit.ToLower() == "y")
                {
                    break;
                }
                Application.DoEvents();
            }
        }
예제 #5
0
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     try
     {
         if (ddlFormat.SelectedValue == "jpg")
         {
             if (ddlConvert.SelectedValue == "html")
             {
                 grabzItClient.HTMLToImage(txtHTML.Text);
             }
             else
             {
                 grabzItClient.URLToImage(txtURL.Text);
             }
         }
         else if (ddlFormat.SelectedValue == "docx")
         {
             if (ddlConvert.SelectedValue == "html")
             {
                 grabzItClient.HTMLToDOCX(txtHTML.Text);
             }
             else
             {
                 grabzItClient.URLToDOCX(txtURL.Text);
             }
         }
         else if (ddlFormat.SelectedValue == "csv")
         {
             if (ddlConvert.SelectedValue == "html")
             {
                 grabzItClient.HTMLToTable(txtHTML.Text);
             }
             else
             {
                 grabzItClient.URLToTable(txtURL.Text);
             }
         }
         else if (ddlFormat.SelectedValue == "gif")
         {
             grabzItClient.URLToAnimation(txtURL.Text);
         }
         else
         {
             if (ddlConvert.SelectedValue == "html")
             {
                 grabzItClient.HTMLToPDF(txtHTML.Text);
             }
             else
             {
                 grabzItClient.URLToPDF(txtURL.Text);
             }
         }
         if (UseCallbackHandler)
         {
             grabzItClient.ScreenShotComplete += grabzIt_ScreenShotComplete;
             grabzItClient.Save(HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath + "GrabzIt.ashx");
             lblMessage.Text     = "Processing...";
             lblMessage.CssClass = string.Empty;
             lblMessage.Style.Add("color", "green");
             lblMessage.Style.Add("font-weight", "bold");
         }
         else
         {
             grabzItClient.SaveTo(Server.MapPath("~/results/" + Guid.NewGuid().ToString() + "." + ddlFormat.SelectedValue));
         }
     }
     catch (Exception ex)
     {
         lblMessage.Text = ex.Message;
         lblMessage.Style.Clear();
         lblMessage.CssClass = "error";
     }
 }