Skip to content

Instantly share code, notes, and snippets.

Created October 24, 2017 03:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Gist to illustrate saving a PNG generated via Sitecore PhantomJS as a PDF.
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using Sitecore.ContentTesting.Pipelines.GetScreenShotForURL;
namespace MyLibrary.GetScreenShotForURL
public class GeneratePdf : GenerateScreenShotProcessor
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
var xgr = XGraphics.FromPdfPage(doc.Pages[0]);
xgr.DrawImage(img, 0, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment