PDF thumbnail generation
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
orpng
. Default:png
.