diff --git a/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertPDFToPDFA.java b/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertPDFToPDFA.java index 294a757b7..89282b925 100644 --- a/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertPDFToPDFA.java +++ b/stirling-pdf/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertPDFToPDFA.java @@ -106,7 +106,7 @@ public class ConvertPDFToPDFA { Path tempInputFile = null; byte[] fileBytes; Path loPdfPath = null; // Used for LibreOffice conversion output - File preProcessedFile; + File preProcessedFile = null; int pdfaPart = 2; try { @@ -129,7 +129,6 @@ public class ConvertPDFToPDFA { if (!missingFonts.isEmpty() || needImgs) { // Run LibreOffice conversion to get flattened images and embedded fonts loPdfPath = runLibreOfficeConversion(preProcessedFile.toPath(), pdfaPart); - preProcessedFile = loPdfPath.toFile(); } } fileBytes = @@ -149,6 +148,9 @@ public class ConvertPDFToPDFA { if (loPdfPath != null && loPdfPath.getParent() != null) { FileUtils.deleteDirectory(loPdfPath.getParent().toFile()); } + if (preProcessedFile != null) { + Files.deleteIfExists(preProcessedFile.toPath()); + } } }