-
public class PDFThumbnailGeneratorUtility class for generating PDF thumbnails from various document sources.
This class provides static methods to generate thumbnails from PDF documents using different sources like File, Uri, ByteArray, InputStream, or asset paths. All operations are performed on background threads for optimal performance.
Example usage:
// Generate a simple thumbnail val thumbnail = PDFThumbnailGenerator.generateThumbnail(context, file) // Generate with custom configuration val config = ThumbnailConfig( width = 300, height = 400, quality = Bitmap.Config.ARGB_8888, annotationRendering = true ) val thumbnail = PDFThumbnailGenerator.generateThumbnail(context, file, config = config) // Generate multiple thumbnails val thumbnails = PDFThumbnailGenerator.generateThumbnails( context, file, listOf(0, 1, 2) )
-
-
Field Summary
Fields Modifier and Type Field Description public final static PDFThumbnailGeneratorINSTANCE
-
Method Summary
Modifier and Type Method Description final BitmapgenerateThumbnail(Context context, Object source, Integer pageIndex, ThumbnailConfig config, String password, Boolean useCache)Generates a thumbnail for a specific page of a PDF document. final List<Bitmap>generateThumbnails(Context context, Object source, List<Integer> pageIndices, ThumbnailConfig config, String password, Boolean useCache)Generates thumbnails for multiple pages of a PDF document. final IntegergetPageCount(Context context, Object source, String password)Gets the total number of pages in a PDF document. final UnitclearCache()Clears the thumbnail cache to free memory. final IntegergetCacheSize()Gets the current cache size in KB. -
-
Method Detail
-
generateThumbnail
final Bitmap generateThumbnail(Context context, Object source, Integer pageIndex, ThumbnailConfig config, String password, Boolean useCache)
Generates a thumbnail for a specific page of a PDF document.
- Parameters:
context- The application context.source- The PDF document source (File, Uri, ByteArray, InputStream, String asset path, or DocumentSource).pageIndex- The page index to generate thumbnail for (0-based).config- The thumbnail configuration.password- Optional password for encrypted PDFs.useCache- Whether to use caching for improved performance.
-
generateThumbnails
final List<Bitmap> generateThumbnails(Context context, Object source, List<Integer> pageIndices, ThumbnailConfig config, String password, Boolean useCache)
Generates thumbnails for multiple pages of a PDF document.
- Parameters:
context- The application context.source- The PDF document source.pageIndices- List of page indices to generate thumbnails for (0-based).config- The thumbnail configuration for all pages.password- Optional password for encrypted PDFs.useCache- Whether to use caching for improved performance.
-
getPageCount
final Integer getPageCount(Context context, Object source, String password)
Gets the total number of pages in a PDF document.
- Parameters:
context- The application context.source- The PDF document source.password- Optional password for encrypted PDFs.
-
clearCache
final Unit clearCache()
Clears the thumbnail cache to free memory.
-
getCacheSize
final Integer getCacheSize()
Gets the current cache size in KB.
-
-
-
-