4 votes

PDF Thumbnails

Don't you just find it annoying when you design a brand new website with some nice styling for your customers, and they start to upload pdf files instead of writing the text in the RTE? Sometimes it's necessary. when the customer received the pdf from a third party, and this is where this package can give you a compromise.

How does it work:

When you upload a pdf file, this package will generate jpg thumbnails of all pages in a subfolder of pdf file media folder. Through an extension you get the list of thumbsnails associated with the pdf file, and you can choose which to render of the page

How to install:

  1. Install the package
  2. Done

There is a macro included that demonstrates how to get the thumbnails

Technical info:

The package includes an extension function called GetMedia, that works just like the umbraco.library version. Actually it calls the umbraco.library version and adds the thumbnails xml snippet the returned xml. This is cached just like the umbraco.library version and uses the UmbracoLibraryCacheDuration setting from umbracoSettings.config.

The xml format is this:

<File id="1086" version="704a1724-b86e-4dff-bfbc-897b01a830e7" parentID="1055" level="2" writerID="0" nodeType="1033" template="0" sortOrder="30" createDate="2013-06-19T15:43:39" updateDate="2013-06-19T15:43:39" nodeName="Theumbraco6requestpipeline" urlName="theumbraco6requestpipeline" writerName="admin" nodeTypeAlias="File" path="-1,1055,1086">  <umbracoFile>/media/110/TheUmbraco6RequestPipeline.pdf</umbracoFile>  <umbracoExtension>pdf</umbracoExtension>  <umbracoBytes>2091318</umbracoBytes>  <pdfThumbnails>    <file id="1">/media/110/pdfthumbs/TheUmbraco6RequestPipeline_page_1.jpg</file>    <file id="2">/media/110/pdfthumbs/TheUmbraco6RequestPipeline_page_2.jpg</file>    <file id="3">/media/110/pdfthumbs/TheUmbraco6RequestPipeline_page_3.jpg</file>    .......  </pdfThumbnails></File>

XSLT Sample:

<xsl:param name="currentPage"/><xsl:variable name="mediaItem" select="/macro/mediaItem"/><xsl:template match="/"><xsl:if test="$mediaItem">    <xsl:variable name="pdf" select="Flexit.PdfThumbnails:GetMedia($mediaItem/File/@id,0)"/>    <h2><xsl:value-of select="$pdf/@nodeName"/></h2>    <a href="{$pdf/umbracoFile}">Get full PDF here</a>    <xsl:for-each select="$pdf//pdfThumbnails/file" >        <img src="{.}"/>    </xsl:for-each></xsl:if></xsl:template>

Razor example

@inherits umbraco.MacroEngines.DynamicNodeContext@using Flexit.PdfThumbnails;@{    var pdf = PDFHelper.GetMedia(1086);    <a href="@pdf.Media.Url">Link to full PDF</a>    foreach (var thumb in pdf.PdfThumbs)    {        <img src="@thumb.fileName">    }}

The following libraries/code has been used to create this package:
GhostScript (http://www.ghostscript.com/)
GhostScriptSharp wrapper (https://github.com/cbadke/ghostscriptsharp)

This has only been tested on 6.1.1

Version history:

1.0: Added Razor helper
0.9 Initial release

Screenshots

Package owner

Bo Kingo Damgaard

Bo Kingo Damgaard

Bo has 455 karma points

Package Compatibility

This package is compatible with the following versions as reported by community members who have downloaded this package:
Untested or doesn't work on Umbraco Cloud
8.3.x (untested)
8.2.x (untested)
8.1.x (untested)
8.0.x (untested)
7.15.x (untested)
7.14.x (untested)
7.13.x (untested)
7.12.x (untested)
7.11.x (untested)
7.10.x (untested)
7.9.x (untested)
7.8.x (untested)
7.7.x (untested)
7.6.x (untested)
7.5.x (0%)
7.4.x (50%)
7.3.x (untested)
7.2.x (untested)
7.1.x (untested)
7.0.x (untested)
6.1.x (100%)
6.0.x (untested)

You must login before you can report on package compatibility.

Package Information

  • Package owner: Bo Kingo Damgaard
  • Created: 21/06/2013
  • Current version 1.0
  • License MIT
  • Downloads: 1772

External resources