Recently I was asked to display thumbnails of PDF files stored in a SharePoint library. Although it seemed difficult at first the solution was relatively simple but needed some C# and some XSLT coding. Also needed was a PDF processor to create the thumbnails and instead of using a commercial application I managed to do it with GNU GhostScript. In my case the PDF's were well known file names but in this blog I'm suggesting how it could be done dynamically.
The solution is to create a list of PDF and thumbnail files in an XML file and then to create a corresponding XSLT to display the thumbnails as links to PDF files using the standard XML Web Part. You have to have the thumbnails pre-created for each of the PDF files.
Using a PDF processor you'll create the thumbnails in say PNG format. This can be automated using an event-hander on the library that would also update the XML file although initially this could be done manually also. The XML could look like this:
and the XSLT would output for each item something like:
The XSLT does not change as files are added and removed from the library - only the XML changes. The total files in the library would then be eight:
This is just the basic idea and details will obviously change depending on your requirements.
Tips and Tricks
When I get a chance I will include some pictures in this blog.
The solution is to create a list of PDF and thumbnail files in an XML file and then to create a corresponding XSLT to display the thumbnails as links to PDF files using the standard XML Web Part. You have to have the thumbnails pre-created for each of the PDF files.
Using a PDF processor you'll create the thumbnails in say PNG format. This can be automated using an event-hander on the library that would also update the XML file although initially this could be done manually also. The XML could look like this:
<pdf_list>
<item name='pdf_file_01' />
<item name='pdf_file_02' />
<item name='pdf_file_03' />
</pdf_list>
and the XSLT would output for each item something like:
<a href='pdf_file_99.pdf' target='_blank'>
<img src='pdf_file_99.png' alt='thumbnail' />
</a>
The XSLT does not change as files are added and removed from the library - only the XML changes. The total files in the library would then be eight:
_list.xml
_list.xslt
pdf_file_01.pdf
pdf_file_01.png
pdf_file_02.pdf
pdf_file_02.png
pdf_file_03.pdf
pdf_file_03.png
This is just the basic idea and details will obviously change depending on your requirements.
Tips and Tricks
- The XML could contain additional metadata about the PDF files that could be displayed along with the thumbnail.
- Create a bitmap in a large resolution and then resize it otherwise creating the a small thumbnail from a PDF may result in not so good quality.
- To upload thumbnails map a drive to the SharePoint library using net use x: http://host/web for which you will need Windows WebClient service running.
- To dynamically arrange the thumbnails depending on the size of the end user's screen make use of HTML <DIV> instead of tables.
- It is possible to redesign the XSLT to, for example, display a slide show of the thumbnails as links to PDF using VBScript or JavaScript.
- Filter the default view of the SharePoint library to only show PDF files and hide PNG and XML / XSLT files.
When I get a chance I will include some pictures in this blog.
7 comments:
Hi Tushar,
Can you please send me the code on doing this (pdf preview) as I have the same requirement and I am struggling since days to have this solution implemented in our MOSS 07environment
Thanks heaps in advance.
Regards
Chandra
Sorry but there are a number of source files involved and I did not want to publish source files on this blog.
I cannot find your email address so I refer you to command line arguments for GhostScript. XSLT is fairly straightforward.
Hi Tushar,
I need to do this same thing. My big problem is how to address the pdf files within sharepoint - I actually have quite a bit of reusable code for generating and manipulating pdfs, but I'm not sure how to apply it to files within sharepoint. Could you help point me in the right direction (I'm using moss 2010, but even help with the 2007 would be fantastic).
Hi Drew, Sorry I missed your post, please see my email to you, thanks Tushar
Hi Tushar
Great blog. Im working on a similar solution in Sharepoint Founadation 2010. If it is not too much to ask, I would be very interested in having a look at your solution too.
Thanks
Torben
Sorry but I cannot show the solution 'cos it was done for an intranet some time ago.
I understand. Thanks for your quick reply.
Brgds
Torben
Post a Comment