public void PrintGoogle() { var pdf = new GeckoPdf(new GeckoPdfConfig()); var bytes = pdf.Convert("https://google.com"); Assert.IsTrue(bytes.Length > EmptyDocLength); GeckoPdf.UnloadGecko(); }
public void PrintW3Html() { using (var client = new HttpClient()) { var url = "https://www.w3.org"; var r = client.GetStringAsync(url); r.Wait(); var pdf = new GeckoPdf(new GeckoPdfConfig()); var bytes = pdf.ConvertHtml(url, r.Result, null, null); Assert.IsTrue(bytes.Length > EmptyDocLength); GeckoPdf.UnloadGecko(); } }
public void PrintMultipleSitesAtOnce() { var sites = new string[] { "https://google.com", "https://www.w3.org", "https://www.microsoft.com", "https://github.com/", "https://www.mozilla.org" }; foreach (var site in sites) { Task.Run(() => { var pdf = new GeckoPdf(new GeckoPdfConfig()); var bytes = pdf.Convert(site); Assert.IsTrue(bytes.Length > EmptyDocLength); }); } }
public override void ExecuteResult(ControllerContext context) { var headers = context.HttpContext.Request.Headers; var cookies = context.HttpContext.Request.Cookies; var geckoCookies = new List <GeckoCookie>(); foreach (var key in cookies.AllKeys) { var c = cookies[key]; geckoCookies.Add(new GeckoCookie { Name = c.Name, Value = c.Value, Path = c.Path, ExpiresUnix = DateTimeToUnixTimestamp(c.Expires), HttpOnly = c.HttpOnly, Secure = c.Secure }); } var viewName = ViewName; if (string.IsNullOrEmpty(viewName)) { viewName = context.RouteData.GetRequiredString("action"); } var viewResult = GetView(context, viewName, MasterName); var html = context.GetHtmlFromView(viewResult, viewName, Model); var tempDir = context.HttpContext.Server.MapPath("~/App_Data/temp"); var tempFile = Path.Combine(tempDir, Guid.NewGuid().ToString() + ".tmp"); var bytes = new GeckoPdf(_config).ConvertHtml(context.HttpContext.Request.Url.AbsoluteUri, html, null, geckoCookies, tempFile); var response = PrepareResponse(context.HttpContext.Response); response.OutputStream.Write(bytes, 0, bytes.Length); }