Creating thumbnails for PDFs
OpenCms provides a special tag for PDF thumbnail generation: You just provide the PDF, the thumbnail should be generated for, the size and the format (png or jpg) of the resulting thumbnail and the thumbnail will be generated if requested, and reachable via the URL rendered by special tag.
Here we provide detailed information on how to use the tag and point to some technical details.
How to generate a PDF thumbnail?
Thumbnails for PDFs are generated in a JSP via the tag <cms:pdfthumbnail>
. The tag takes the following attributes, specifying the PDF file used for the thumbnail generation and also some attributes of the thumbnail:
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
.
Technical details
PDF thumbnails are not stored in the VFS. When a <cms:pdfthumbnail>
tag is rendered, a special link to the, not yet present, thumbnail is generated. If the link is requested the first time, the thumbnail is generated. If it is requested again, a cached version of the thumbnail is served. The cached versions are stored on the server's RFS in the folder {webapp home}/WEB-INF/pdfcache
. The cache is cleared, if the PDF document used for the thumbnail is altered.
The interesting code for the PDF generation is found in the module org.opencms.pdfutils
. The class for exposing the tag is found here.