Sample Code snippet:
private String convertToPdfIfRequired(String originalFilePath, String sharedDirectory, int sortOrder) {
if (originalFilePath == null || sharedDirectory == null) {
log.error(“Original file path or shared directory is null.”);
return null;
}
String extension = originalFilePath.substring(originalFilePath.lastIndexOf('.') + 1).toLowerCase();
if (!List.of("doc", "docx", "xls", "xlsx").contains(extension)) {
return originalFilePath; // Return original file if it's already a PDF
}
String pdfFilePath = Paths.get(sharedDirectory, sortOrder + "_converted.pdf").toString();
try (Converter converter = new Converter(originalFilePath)) {
PdfConvertOptions options = new PdfConvertOptions();
converter.convert(pdfFilePath, options);
log.info("Converted {} to PDF: {}", originalFilePath, pdfFilePath);
// Delete the original file after successful conversion
File originalFile = new File(originalFilePath);
if (originalFile.exists() && originalFile.delete()) {
log.info("Deleted original file: {}", originalFilePath);
} else {
log.warn("Failed to delete original file: {}", originalFilePath);
}
return pdfFilePath;
} catch (Exception e) {
log.error("Failed to convert {} to PDF.", originalFilePath, e);
return null;
}
}
The application gets stuck on the following line:
converter.convert(pdfFilePath, options);
Observations:
It works fine local windows environment.
Java version: 17
GroupDocs version: 24.11 (also tested with the latest version, 25.2).
It worked successfully after downgrading GroupDocs to version 23.6.
Questions:
- Why does the convert method not work as expected in the latest release versions?
- Is there an alternative approach to resolve this issue?
- If we finalize using version 23.6, is it a stable version, or are we missing any major feature updates?
We appreciate your support in resolving this issue.