Link

Hints to optimise JPedal performance on a server

This tutorial suggests some useful tricks to tweak performance for JPedal.

1. Use Random Access open methods if possible (file or string) not URL or byte[] to open a PDF file

PDF files are designed to be accessed using RandomAccess. If JPedal can access via RandomAccess, it can just jump around the file structure that is our recommendation. Using the byte[] method is fast once loaded but needs more memory and needs the whole PDF to be loaded first. The URL method requires the whole PDF file to be read and cached to a local file.

2. Keep local images in memory when decoding a PDF file

By default, all images over 16384 bytes in size are cached in a local encrypted file until needed rather than being held in memory. This setting can be altered by changing the value of the static variable PdfFileReader.alwaysCacheInMemory. A value of -1 will keep everything in memory.

There is a code example showing how to convert PDF to Image in memory on this page.

3. Optimise Image output for speed over file size

When converting PDF to any image format, the default settings for JPedal will create smaller output image files (which is slower). If file size is not important, this can be changed. This is documented in our examples showing how to output PDF to Image.

4. Avoid creating images which are bigger than needed

The biggest performance hit in Java is generally the creation of a BufferedImage for rendering, with larger BufferedImages taking longer. JPedal includes 2 ready to run class to generate images which are documented settings.

5. Using multiple-threading

Memory permitting, ConvertPagesToImages and the other examples should be thread-safe (along with PdfDecoderServer). We recommend you create the instance inside a thread, do not try to share an instance between threads.