Class CmsPdfThumbnailGenerator


  • public class CmsPdfThumbnailGenerator
    extends java.lang.Object
    Class for generating thumbnails from PDF documents using the PDFBox library.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] generateThumbnail​(java.io.InputStream pdfInputStream, int boxWidth, int boxHeight, java.lang.String imageFormat, int pageIndex)
      Generates the image data for a thumbnail from a PDF.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • generateThumbnail

        public byte[] generateThumbnail​(java.io.InputStream pdfInputStream,
                                        int boxWidth,
                                        int boxHeight,
                                        java.lang.String imageFormat,
                                        int pageIndex)
                                 throws java.lang.Exception
        Generates the image data for a thumbnail from a PDF.

        The given width and height determine the box in which the thumbnail should fit. The resulting image will always have these dimensions, even if the aspect ratio of the actual PDF page is different from the ratio of the given width and height. In this case, the size of the rendered page will be reduced, and the rest of the image will be filled with blank space.

        If one of width or height is negative, then that dimension is chosen so the resulting aspect ratio is the aspect ratio of the PDF page.

        Parameters:
        pdfInputStream - the input stream for reading the PDF data
        boxWidth - the width of the box in which the thumbnail should fit
        boxHeight - the height of the box in which the thumbnail should fit
        imageFormat - the image format (png, jpg, gif)
        pageIndex - the index of the page for which to render the thumbnail (starting at 0)
        Returns:
        the image data for the thumbnail, in the given image format
        Throws:
        java.lang.Exception - if something goes wrong