Manage memory with Overflow CompareResult implementations
masterComparing large PDFs can consume significant memory because images are held in RAM. To prevent OutOfMemoryError, use specialized CompareResult implementations that swap pages to disk.
Available Implementations
CompareResultWithPageOverflow: Swaps every 10 pages (default) into a partial PDF and merges them at the end. This is a good balance of performance and memory.CompareResultWithMemoryOverflow: Swaps pages to disk when the JVM heap reaches a critical threshold (default is 70% of max heap).
Usage:
new PdfComparator("expected.pdf", "actual.pdf", new CompareResultWithPageOverflow()).compare();Advanced Memory Tuning (via application.conf)
If using the overflow implementations, you can tune these settings in an application.conf file:
imageCacheSizeCount: Number of images cached by PdfBox.maxImageSizeInCache: Max size of an image to be cached.mergeCacheSizeMB: Memory cache for the merge process.swapCacheSizeMB: Memory cache for partial writes.documentCacheSizeMB: Cache for loaded documents.overallTimeoutInMinutes: Safety timeout to detect deadlocks.executorTimeoutInSeconds: Timeout for executors after overall timeout is reached.