Caching images to create smaller PDFs and requiring less memory to generate them, inspired by #99 and based on #120