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:
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