Search the documentation
 Show GitHub edit links  Hide GitHub edit links
In OpenCms since: 9.5 Documented since: 9.5 Latest revision for: 9.5 Valid for OpenCms: 10.5.2

For PDF files stored in the VFS, thumbnails can be generated on the fly. Here we show you an example on how to generate a thumbnail and use it as download button for the original PDF file.

The result

 

Get a PDF by clicking on it's thumbnail

Download the PDF file by clicking on the automatically generated thumbnail below.

 

Example resources and the interesting spots

Generating the thumbnail is done by just one tag in the formatter of the demo article above. Here's the formatters source code:

<%@page buffer="none" session="false" taglibs="c,cms" %>
<cms:formatter var="content" val="value">
<div style="margin-bottom:30px;">
    <div class="headline">
		<h3>${value.Title}</h3>       
	</div>
	<c:if test="${value.PDF.exists}">
		<div style="float:right;width:40%;text-align:center;">
			 <a href="<cms:link>${value.PDF}</cms:link>"
				target="pdf">
				<img src='<cms:pdfthumbnail file="${value.PDF}" height="200" format="png" />' alt="Download PDF" title="Download PDF" />
			</a>
		</div>
	</c:if>
    <div>
        ${value.Text}
    </div>
	<div style="clear:right;"></div>
</div>
</cms:formatter>

The interesting part happens in the <img> tag: Here the <cms:pdfthumbnail> tag is used for the attribute src. The tag expands to a special link. When the link is requested for the first time, the thumbnail is generated and made available under that link. If the link is requested again, the cached thumbnail is returned.

The PDF used to generate the thumbnail and some attributes of the generated thumbnail are specified via the attributes of <cms:pdfthumbnail>.

Attributes of <pdf:thumbnail>
file

VFS URI of the PDF for which the thumbnail should be created.

height (optional, if width is given)

Height of the generated thumbnail. Given as integer value, specifying the number of pixels. By default the height is set to -1, which means that it is chosen automatically dependent on the PDF.

width (optional, if height is given)

Width of the generated thumbnail. Given as integer value, specifying the number of pixels. By default the width is set to -1, which means that it is chosen automatically dependent on the PDF.

format (optional)

Format of the generated thumbnail. Either jpg or png. Default:  png.

You can improve this page

Please contribute your suggestions or comments regarding this topic on our wiki. For support questions, please use the OpenCms mailing list or go for professional support.