Creating thumbnails from the front page of a PDF with ghostscript

Automation is such as wonderful thing.

  1. install Ghostscript to your computer. https://ghostscript.com/download/gsdnld.html
  2. Create a C# console app
  3. Copy the following code into your app and replace <<VERSION NUMER>> with your version number.
  4. Pass in the link to the PDF file, the folder name and the file name.
 public void PdfToJpg(string inputPDFFile, string outputImagesPath, string filename)
 {
     string ghostScriptPath = $"C:\Program Files (x86)\gs\gs<<VERSION NUMBER>>\bin\gswin32.exe";
     string ars = $"-dNOPAUSE -sDEVICE=jpeg -dFirstPage=1 -dLastPage=1 -r102.4 -o \"{outputImagesPath}\\{filename}.jpg\" -sPAPERSIZE=a4 \"{inputPDFFile}\"";
     Process proc = new Process();
     proc.StartInfo.FileName = ghostScriptPath;
     proc.StartInfo.Arguments = ars;
     proc.StartInfo.CreateNoWindow = true;
     proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
     proc.Start();
     proc.WaitForExit();
 }

Wrapping an image with a link in Sitecore mvc

When wrapping an image with a link, you will need to pass the context into the field. In your view, put the following code.

 
@using Sitecore.Mvc.Presentation
@using Sitecore.Mvc
@model Sitecore.Sharedsource.Mvc.Presentation.RenderingModel

@Html.Sitecore().BeginField("Link", Model.Rendering.Item, new { haschildren = true })
 @Html.Sitecore().Field("Image", Model.Rendering.Item)
 @Html.Sitecore().EndField()