Hello Aspose Team,
I’m using Aspose.Words, Aspose.Cells, and Aspose.Slides for Java to convert documents to PDF Spring Boot application.
Problem:
Some large or complex documents take too long to convert (>5 minutes), and I need to cancel/timeout these operations to prevent resource exhaustion. However, standard Java thread interruption doesn’t work because Aspose’s conversion methods don’t respond to Thread.interrupt().
Current Code:
ExecutorService executor = Executors.newFixedThreadPool(6);
Future future = executor.submit(() -> {
Document doc = new Document(inputStream);
doc.save(outputFile.getAbsolutePath(), SaveFormat.PDF);
return null;
});
try {
future.get(5, TimeUnit.MINUTES);
} catch (TimeoutException e) {
future.cancel(true); // ❌ This doesn't stop Aspose conversion
// Thread continues running in background
}
@aygun.safar
You’re seeing that a long‑running save call cannot be stopped with Thread.interrupt() or Future.cancel(true) because the Aspose conversion APIs do not expose a cancellation or interrupt method [2].
What’s available today
-
Run the conversion in a separate process – launch a new JVM (or OS process) to perform the conversion. If the timeout expires, kill that process. This isolates the task and frees the resources used by the conversion.
-
Process the document in smaller chunks where possible. For example, with Aspose Slides you can save slides in batches instead of converting the whole presentation at once [3]. A similar approach can be applied to large Excel workbooks or Word documents if you can split them logically.
-
Monitor and limit resources – configure memory limits for the conversion process or the JVM to prevent host exhaustion when a conversion runs longer than expected.
Feature roadmap
A feature request (WORDSNET‑24743) for lazy conversion / cancellation has been logged, and some related issues were addressed in the Aspose.Words 23.2 update [7]. However, a public API to abort an ongoing conversion is still not provided.
Bottom line
At present there is no built‑in way to cancel a conversion directly in Aspose.Words, Aspose.Cells, or Aspose.Slides. You’ll need to use one of the work‑arounds above (isolated process, chunked processing, resource limits) or wait for a future release that adds the requested cancellation capability.
@aygun.safar In Aspose.Words you can use IDocumentLoadingCallback to interrupt document loading process. Also, you can use IDocumentSavingCallback to cancel save operation.
Upon saving document to PDF or any other fixed page formats, however, the most time is taken by document layout process than by saving operation. You can interrupt the layout process using IPageLayoutCallback .
I will move your topic into Aspose.Total category, so my colleagues from Aspose.Cells and Aspose.Slides teams answer from their perspective.
1 Like
@aygun.safar,
In Aspose.Cells, you can stop conversion of Workbook to various formats like PDF, HTML, etc. using the InterruptMonitor object when it is taking too long. The conversion process is often both CPU and Memory intensive and it is often useful to halt it when resources are limited. You can use InterruptMonitor both for stopping conversion as well as to stop loading huge workbook. Please use Workbook.InterruptMonitor property for stopping conversion and LoadOptions.InterruptMonitor property for loading huge workbook. See the document with example code for your reference. Stop conversion or loading using InterruptMonitor when it is taking too long|Documentation
1 Like
@alexey.noskov @amjad.sahi thank you for your previous answers!
I successfully implemented conversion timeout functionality for Word and Excel:
- Word: Using IPageLayoutCallback
- Excel: Using InterruptMonitor
Now I need to implement the same timeout mechanism for PowerPoint presentations. How can I achieve this with Aspose.Slides? Is there a similar callback/monitor interface available?
@aygun.safar,
It’s good to hear that you have implemented the timeout feature for Aspose.Words and Aspose.Cells.
Regarding Aspose.Slides, one of my colleagues from the Aspose.Slides team will review the task of PDF rendering from PowerPoint presentations and assist you soon, @andrey.potapov FYI.
1 Like
@aygun.safar,
Unfortunately, Aspose.Slides does not provide its own interruption mechanism for presentation-to-PDF conversions.
Please try using the following code snippet:
ExecutorService executor = Executors.newFixedThreadPool(6);
final InterruptionTokenSource tokenSource = new InterruptionTokenSource();
Future<Void> future = executor.submit(() -> {
LoadOptions loadOptions = new LoadOptions();
loadOptions.setInterruptionToken(tokenSource.getToken());
Presentation presentation = new Presentation("sample.pptx", loadOptions);
try {
presentation.save("output.pdf", SaveFormat.Pdf);
return null;
} finally {
presentation.dispose();
}
});
try {
future.get(5, TimeUnit.MINUTES);
} catch (TimeoutException e) {
tokenSource.interrupt(); // Request Aspose.Slides to stop the operation.
future.cancel(true); // Optional: also interrupt the worker thread.
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
// Handle conversion failure.
} finally {
executor.shutdownNow();
}
Hello again, thank you for your answer
I’m converting PPTX to PDF in a Spring Boot microservice with a timeout mechanism using InterruptionTokenSource. The problem is that after calling interrupt(), the save operation continues to run in the background thread and completes successfully, which means:
- The caller receives a timeout exception, but the thread keeps working
- The temp output file cannot be deleted because the background thread still holds a lock on it
Environment:
- Aspose.Slides for Java 25.1 (also tested on 24.x)
- Java 17, Spring Boot 3.x
- Windows Server / Linux (same behavior on both)
Code:
Helper class that wraps InterruptionTokenSource with timeout tracking:
public class SlidesProgressMonitor {
private final InterruptionTokenSource tokenSource;
private final long timeoutMillis;
private final long startTime;
private final String fileName;
public SlidesProgressMonitor(long timeoutMillis, String fileName) {
this.tokenSource = new InterruptionTokenSource();
this.timeoutMillis = timeoutMillis;
this.startTime = System.currentTimeMillis();
this.fileName = fileName;
}
public InterruptionTokenSource getTokenSource() {
return tokenSource;
}
public long getElapsedTime() {
return System.currentTimeMillis() - startTime;
}
public long getTimeoutMillis() {
return timeoutMillis;
}
public String getFileName() {
return fileName;
}
public void interruptIfNeeded() {
tokenSource.interrupt();
}
}
Conversion method using Future with timeout:
public void slideToPdf(InputStream inputStream, File outputFile, long timeoutMillis) throws Exception {
SlidesProgressMonitor monitor = new SlidesProgressMonitor(timeoutMillis, outputFile.getName());
Future<Void> future = executorService.submit(() -> {
com.aspose.slides.LoadOptions loadOptions = new com.aspose.slides.LoadOptions();
loadOptions.setInterruptionToken(monitor.getTokenSource().getToken());
Presentation presentation = new Presentation(inputStream, loadOptions);
try {
presentation.save(outputFile.getAbsolutePath(), com.aspose.slides.SaveFormat.Pdf);
return null;
} finally {
presentation.dispose();
}
});
try {
future.get(timeoutMillis, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
monitor.interruptIfNeeded(); // <-- This does not stop the save
future.cancel(true);
throw new RuntimeException("Conversion timed out: " + outputFile.getName());
} catch (ExecutionException e) {
throw (Exception) e.getCause();
}
}
Logs showing the issue:
09:30:36.892 WARN - tokenSource.interrupt() called (elapsed: 5027ms, limit: 5000ms)
09:30:36.903 WARN - outputFile.delete() failed — file still locked by background thread
09:30:36.918 ERROR - TimeoutException thrown to caller
09:30:37.091 INFO - presentation.save() completed successfully (~200ms AFTER interrupt)
As you can see, interrupt() was called at 09:30:36.892, but the save operation completed at 09:30:37.091 — roughly 200ms later. The thread did not respect the interruption token.
Is there a way to force-stop the save operation immediately?
@aygun.safar,
Thank you for the additional information.
We have opened the following new ticket(s) in our internal issue tracking system and will investigate the case according to the terms mentioned in Free Support Policies.
Issue ID(s): SLIDESJAVA-39776
@aygun.safar,
Please try using the following code snippet:
final InterruptionTokenSource tokenSource = new InterruptionTokenSource();
Runnable interruption = new Runnable() {
public void run() {
LoadOptions loadOptions = new LoadOptions();
loadOptions.setInterruptionToken(tokenSource.getToken());
Presentation presentation = new Presentation("sample.pptx", loadOptions);
try{
presentation.save("sample.pdf", SaveFormat.Pdf);
}
finally {
presentation.dispose();
}
}
};
Thread thread = new Thread(interruption);
thread.start(); // run the action in a separate thread
Thread.sleep(5000); // timeout
tokenSource.interrupt(); // stop the conversion
System.out.println(tokenSource.getToken().isInterruptionRequested());
See also:
Support For Interruptable Library|Aspose.Slides Documentation