mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-14 10:34:06 +02:00
migrate exportUpdatedPages from bytes to stream (#6201)
Co-authored-by: ConnorYoh <[email protected]>
This commit is contained in:
co-authored by
ConnorYoh
parent
2c15044dfa
commit
2399da6893
+7
-4
@@ -184,8 +184,6 @@ public class ConvertPdfJsonController {
|
||||
|
||||
validateJobAccess(jobId);
|
||||
|
||||
byte[] pdfBytes = pdfJsonConversionService.exportUpdatedPages(jobId, document);
|
||||
|
||||
String baseName =
|
||||
(filename != null && !filename.isBlank())
|
||||
? FILE_EXTENSION_PATTERN
|
||||
@@ -197,13 +195,18 @@ public class ConvertPdfJsonController {
|
||||
.orElse("document");
|
||||
String docName = baseName.endsWith(".pdf") ? baseName : baseName + ".pdf";
|
||||
TempFile tempOut = tempFileManager.createManagedTempFile(".pdf");
|
||||
try (OutputStream os = Files.newOutputStream(tempOut.getPath())) {
|
||||
pdfJsonConversionService.exportUpdatedPages(jobId, document, os);
|
||||
} catch (Exception e) {
|
||||
tempOut.close();
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
Files.write(tempOut.getPath(), pdfBytes);
|
||||
return WebResponseUtils.pdfFileToWebResponse(tempOut, docName);
|
||||
} catch (Exception e) {
|
||||
tempOut.close();
|
||||
throw e;
|
||||
}
|
||||
return WebResponseUtils.pdfFileToWebResponse(tempOut, docName);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/pdf/text-editor/page/{jobId}/{pageNumber}")
|
||||
|
||||
@@ -6490,7 +6490,8 @@ public class PdfJsonConversionService {
|
||||
objectMapper.writeValue(out, pageFonts);
|
||||
}
|
||||
|
||||
public byte[] exportUpdatedPages(String jobId, PdfJsonDocument updates) throws IOException {
|
||||
public void exportUpdatedPages(String jobId, PdfJsonDocument updates, OutputStream outputStream)
|
||||
throws IOException {
|
||||
if (jobId == null || jobId.isBlank()) {
|
||||
throw new IllegalArgumentException("jobId is required for incremental export");
|
||||
}
|
||||
@@ -6513,7 +6514,8 @@ public class PdfJsonConversionService {
|
||||
log.debug(
|
||||
"Incremental export requested with no page updates; returning cached PDF for jobId {}",
|
||||
jobId);
|
||||
return cached.getPdfBytes();
|
||||
outputStream.write(cached.getPdfBytes());
|
||||
return;
|
||||
}
|
||||
|
||||
try (PDDocument document = pdfDocumentFactory.load(cached.getPdfBytes(), true)) {
|
||||
@@ -6580,7 +6582,8 @@ public class PdfJsonConversionService {
|
||||
log.debug(
|
||||
"Incremental export for jobId {} resulted in no page updates; returning cached PDF",
|
||||
jobId);
|
||||
return cached.getPdfBytes();
|
||||
outputStream.write(cached.getPdfBytes());
|
||||
return;
|
||||
}
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
@@ -6603,7 +6606,7 @@ public class PdfJsonConversionService {
|
||||
"Incremental export complete for jobId {} (pages updated: {})",
|
||||
jobId,
|
||||
updatedPages.stream().map(i -> i + 1).sorted().toList());
|
||||
return updatedBytes;
|
||||
outputStream.write(updatedBytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user