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)); }
protected override void Process(HttpContext context, string filename, string id, string message, string customId, string format) { GrabzItClient grabzItClient = GrabzItClient.Create(ConfigurationManager.AppSettings["ApplicationKey"], ConfigurationManager.AppSettings["ApplicationSecret"]); GrabzItFile file = grabzItClient.GetResult(id); //Ensure that the application has the correct rights for this directory. file.Save(context.Server.MapPath("~/results/" + filename)); }
public ActionResult Handler(string filename, string id, string message, string customId, string format) { GrabzItClient grabzItClient = GrabzItClient.Create(ConfigurationManager.AppSettings["ApplicationKey"], ConfigurationManager.AppSettings["ApplicationSecret"]); GrabzItFile file = grabzItClient.GetResult(id); //Ensure that the application has the correct rights for this directory. file.Save(Server.MapPath("~/results/" + filename)); return(null); }
//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); }
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(); } }