public override void Process(GetScreenShotForURLArgs args) { Assert.IsNotNull(args, nameof(args)); var item = ContextDatabase.GetItem(args.ItemId); if (item == null) { Log.Warn($"Unable to find item {args.ItemId} in database: {ContextDatabase}", this); } using (new DatabaseSwitcher(ContextDatabase)) { var site = ResolveContextSite(item); if (site == null) { Log.Warn($"Unable to find site for item {args.ItemId}", this); } using (new SiteContextSwitcher(new SiteContext(site))) args.Url = WebUtil.GetServerUrl() + LinkManager.GetItemUrl(item); } }
public override void Execute(CommandContext context) { var item = context.Items.FirstOrDefault(); if (item == null) { return; } var args = new GetScreenShotForURLArgs(item.ID); CorePipeline.Run("getScreenShotForURL", args); }
public override void Process(GetScreenShotForURLArgs args) { args.Script = args.Script.Replace(StandardExit, TimeoutExit); var outputFilePath = Sitecore.ContentTesting.Helpers.PathHelper.MapPath(args.OutputFilename).Replace("\\", "\\\\"); // script cleanup args.Script = args.Script.Replace($"page.render('{outputFilePath}');", ""); args.Script = args.Script.Replace("%outfile%", outputFilePath); if (!DirectPdf) { return; } args.Script = args.Script.Replace(".png", ".pdf"); // adjust output file name for later consumption args.OutputFilename = args.OutputFilename.Replace(".png", ".pdf"); }
public override void Process(GetScreenShotForURLArgs args) { var imagePath = Sitecore.ContentTesting.Helpers.PathHelper.MapPath(args.OutputFilename); var pdfPath = imagePath.Replace(".png", ".pdf"); using (var doc = new PdfDocument()) { var img = XImage.FromFile(imagePath); var page = new PdfPage { Height = img.PointHeight, Width = img.PointWidth }; doc.Pages.Add(page); var xgr = XGraphics.FromPdfPage(doc.Pages[0]); xgr.DrawImage(img, 0, 0); doc.Save(pdfPath); } args.OutputFilename = args.OutputFilename.Replace(".png", ".pdf"); }