Gist to illustrate saving a PNG generated via Sitecore PhantomJS as a PDF.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}; | |
doc.Pages.Add(page); | |
var xgr = XGraphics.FromPdfPage(doc.Pages[0]); | |
xgr.DrawImage(img, 0, 0); | |
doc.Save(pdfPath); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment