In this article, we’ll see how to get or set a directory to save temporary images. We’ll also understand the process of cleaning up the temporary images once the image extraction process is finished.
PdfExtractor class creates temporary images while extracting images from a PDF file. Aspose.Pdf.Kit for Java has introduced a class named Settings which allows you to get or set the temporary directory. In order to get the temporary directory you can use getTemporaryDirectory method, while setTemporaryDirectory method allows you to specify the temporary directory. However, you first need to create the temporary directory.
In order to cleanup images after the image extraction process is finished, you only need to call the close method of PdfExtractor class.
The following code snippet shows you how to get or set temporary directory and clean up temporary images.
//create Settings object
Settings setting = new Settings();
//set temporary directory to keep temporary images
//get temporary directory
//extract images using PdfExtractor class
PdfExtractor extractor = new PdfExtractor();
String suffix = ".png";
String path = "out\\";
nt imageCount = 1;
String strImagePath = path + imageCount + suffix;
//call close method to clean up temporary images