Class PdfScreenshotCreator


  • public final class PdfScreenshotCreator
    extends Object
    Helper class for creating images from individual pages of a PDF document or of thee entire PDF document.
    Since:
    7.2.0
    Author:
    XIMA MEDIA GmbH
    • Method Detail

      • createImages

        public static <T> Map<Integer,​T> createImages​(byte[] pdf,
                                                            String password,
                                                            IImageOpts opts,
                                                            IImageMapper<T> mapper)
                                                     throws org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException,
                                                            IOException
        Type Parameters:
        T - Type of the converted image.
        Parameters:
        pdf - PDF document to process.
        password - Password for the document, if encrypted, can be null when not encrypted.
        opts - Options which page to convert.
        mapper - Mapper that is given the raw image of a PDF page into the desired format, e.g. a PNG image or base64 data URL etc.
        Returns:
        A map between the 0-based page index and the generated images.
        Throws:
        org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException - When the PDF is encrypted and the password is wrong.
        IOException - When the PDF document could not be processed.
      • createImages

        public static <T> Map<Integer,​T> createImages​(File pdf,
                                                            String password,
                                                            IImageOpts opts,
                                                            IImageMapper<T> mapper)
                                                     throws org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException,
                                                            IOException
        Type Parameters:
        T - Type of the converted image.
        Parameters:
        pdf - PDF document to process.
        password - Password for the document, if encrypted, can be null when not encrypted.
        opts - Options which page to convert.
        mapper - Mapper that is given the raw image of a PDF page into the desired format, e.g. a PNG image or base64 data URL etc.
        Returns:
        A map between the 0-based page index and the generated images.
        Throws:
        org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException - When the PDF is encrypted and the password is wrong.
        IOException - When the PDF document could not be processed.
      • createImages

        public static <T> Map<Integer,​T> createImages​(InputStream pdf,
                                                            String password,
                                                            IImageOpts opts,
                                                            IImageMapper<T> mapper)
                                                     throws org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException,
                                                            IOException
        Type Parameters:
        T - Type of the converted image.
        Parameters:
        pdf - PDF document to process.
        password - Password for the document, if encrypted, can be null when not encrypted.
        opts - Options which page to convert.
        mapper - Mapper that is given the raw image of a PDF page into the desired format, e.g. a PNG image or base64 data URL etc.
        Returns:
        A map between the 0-based page index and the generated images.
        Throws:
        org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException - When the PDF is encrypted and the password is wrong.
        IOException - When the PDF document could not be processed.
      • createImages

        public static <T> Map<Integer,​T> createImages​(Path pdf,
                                                            String password,
                                                            IImageOpts opts,
                                                            IImageMapper<T> mapper)
                                                     throws org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException,
                                                            IOException
        Type Parameters:
        T - Type of the converted image.
        Parameters:
        pdf - PDF document to process.
        password - Password for the document, if encrypted, can be null when not encrypted.
        opts - Options which page to convert.
        mapper - Mapper that is given the raw image of a PDF page into the desired format, e.g. a PNG image or base64 data URL etc.
        Returns:
        A map between the 0-based page index and the generated images.
        Throws:
        org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException - When the PDF is encrypted and the password is wrong.
        IOException - When the PDF document could not be processed.
      • optsAllPages

        public static IImageOpts optsAllPages​(float dpi)
        Parameters:
        dpi - Resolution in dots-per-inch for the rendered image.
        Returns:
        Options for taking a screenshot of all pages of a PDF document at the given resolution.
      • optsPageNumbers

        public static IImageOpts optsPageNumbers​(float dpi,
                                                 int... pages)
        Parameters:
        dpi - Resolution in dots-per-inch for the rendered image.
        pages - Set of 0-based page indices of the pages to screenshot.
        Returns:
        Options for taking a screenshot of all given pages and at the given resolution.
      • optsPageNumbers

        public static IImageOpts optsPageNumbers​(float dpi,
                                                 Set<Integer> pages)
        Parameters:
        dpi - Resolution in dots-per-inch for the rendered image.
        pages - Set of 0-based page indices of the pages to screenshot.
        Returns:
        Options for taking a screenshot of all given pages and at the given resolution.
      • optsPageRange

        public static IImageOpts optsPageRange​(float dpi,
                                               com.google.common.collect.Range<Integer> range)
        Parameters:
        dpi - Resolution in dots-per-inch for the rendered image.
        range - Range of pages to screenshot.
        Returns:
        Options for taking a screenshot of all pages in the given range and at the given resolution.