コード例 #1
0
ファイル: HomeController.cs プロジェクト: zhatin/grabzit
        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
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     try
     {
         grabzItClient.ScreenShotComplete += grabzIt_ScreenShotComplete;
         if (ddlFormat.SelectedValue == "jpg")
         {
             if (ddlConvert.SelectedValue == "html")
             {
                 grabzItClient.HTMLToImage(txtHTML.Text);
             }
             else
             {
                 grabzItClient.URLToImage(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);
             }
         }
         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");
     }
     catch (Exception ex)
     {
         lblMessage.Text = ex.Message;
         lblMessage.Style.Clear();
         lblMessage.CssClass = "error";
     }
 }
コード例 #3
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();
            }
        }
コード例 #4
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";
     }
 }