Hi, I converted files from pdf to html and got a lot of temp files that generated after the conversion.
These files are not deleted even after a lot of time.
An example of a temp file name is “aspose_44_1566222613932.tmp”.
We want to know how can we delete them in order to save space.
We are using Aspose.PDF for Java 19.7 and have a 30 day trial license.
Here is my code:
private static void convertDocToHtml(File file) {
String outputHtmlFile = new StringBuilder().append(OUTPUT_HTML_FOLDER).append(File.separator).append(FilenameUtils.removeExtension(file.getName())).append(".html").toString();
try {
Document doc = new Document(file.getAbsolutePath());
// Instantiate HTML Save options object
HtmlSaveOptions newOptions = new HtmlSaveOptions();
// Enable option to embed all resources inside the HTML
newOptions.PartsEmbeddingMode = HtmlSaveOptions.PartsEmbeddingModes.EmbedAllIntoHtml;
// This is just optimization for IE and can be omitted
newOptions.LettersPositioningMethod = LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;
newOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
newOptions.FontSavingMode = HtmlSaveOptions.FontSavingModes.SaveInAllFormats;
// Output file path
// Save the output file
doc.save(outputHtmlFile, newOptions);
} catch (final Exception e) {
System.out.println(e);
}
}
Temporary files are created by JDK when reading system fonts, we just handle this process giving Aspose name for such temp files. Also, we have the method to remove all the temp files created by Aspose. But notice please, that JDK can themselves lock some temporary files in cache to prevent from deleting - usually not more than 10 files.
You may use the following code once all Aspose related processes are finished:
com.aspose.pdf.MemoryCleaner.clearAllTempFiles();
Or use the complete memory clearing from static, temp and cached object:
com.aspose.pdf.MemoryCleaner.clear();
We hope this will be helpful. Please feel free to contact us if you need any further assistance.
@Farhan.Raza
Thanks for your answer. Both of the solutions are not good. Actually my ticket was opened after I added the line:
com.aspose.pdf.MemoryCleaner.clearAllTempFiles();
I tried to change it to the second option and all the files were deleted including other temp files that we need.
Can you please give me a better solution that deletes only the temp files that related to Aspose?
As we have mentioned, some files can be locked by JDK itself which may not be deleted. Moreover, the API may not differentiate between files to keep few and delete others so these requirements are out of scope for Aspose.PDF API because of files being managed by JDK.
We hope this will clarify ambiguities, if any. We will be more than glad to assist you if there are any further concerns.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.