Class CmsPdfThumbnailGenerator

java.lang.Object
org.opencms.pdftools.CmsPdfThumbnailGenerator

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

  • Constructor Details

  • Method Details

    • generateThumbnail

      public byte[] generateThumbnail(InputStream pdfInputStream, int boxWidth, int boxHeight, String imageFormat, int pageIndex) throws 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:
      Exception - if something goes wrong