mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 19:33:11 +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);
|
validateJobAccess(jobId);
|
||||||
|
|
||||||
byte[] pdfBytes = pdfJsonConversionService.exportUpdatedPages(jobId, document);
|
|
||||||
|
|
||||||
String baseName =
|
String baseName =
|
||||||
(filename != null && !filename.isBlank())
|
(filename != null && !filename.isBlank())
|
||||||
? FILE_EXTENSION_PATTERN
|
? FILE_EXTENSION_PATTERN
|
||||||
@@ -197,13 +195,18 @@ public class ConvertPdfJsonController {
|
|||||||
.orElse("document");
|
.orElse("document");
|
||||||
String docName = baseName.endsWith(".pdf") ? baseName : baseName + ".pdf";
|
String docName = baseName.endsWith(".pdf") ? baseName : baseName + ".pdf";
|
||||||
TempFile tempOut = tempFileManager.createManagedTempFile(".pdf");
|
TempFile tempOut = tempFileManager.createManagedTempFile(".pdf");
|
||||||
try {
|
try (OutputStream os = Files.newOutputStream(tempOut.getPath())) {
|
||||||
Files.write(tempOut.getPath(), pdfBytes);
|
pdfJsonConversionService.exportUpdatedPages(jobId, document, os);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
tempOut.close();
|
tempOut.close();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
return WebResponseUtils.pdfFileToWebResponse(tempOut, docName);
|
return WebResponseUtils.pdfFileToWebResponse(tempOut, docName);
|
||||||
|
} catch (Exception e) {
|
||||||
|
tempOut.close();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/pdf/text-editor/page/{jobId}/{pageNumber}")
|
@GetMapping(value = "/pdf/text-editor/page/{jobId}/{pageNumber}")
|
||||||
|
|||||||
@@ -6490,7 +6490,8 @@ public class PdfJsonConversionService {
|
|||||||
objectMapper.writeValue(out, pageFonts);
|
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()) {
|
if (jobId == null || jobId.isBlank()) {
|
||||||
throw new IllegalArgumentException("jobId is required for incremental export");
|
throw new IllegalArgumentException("jobId is required for incremental export");
|
||||||
}
|
}
|
||||||
@@ -6513,7 +6514,8 @@ public class PdfJsonConversionService {
|
|||||||
log.debug(
|
log.debug(
|
||||||
"Incremental export requested with no page updates; returning cached PDF for jobId {}",
|
"Incremental export requested with no page updates; returning cached PDF for jobId {}",
|
||||||
jobId);
|
jobId);
|
||||||
return cached.getPdfBytes();
|
outputStream.write(cached.getPdfBytes());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try (PDDocument document = pdfDocumentFactory.load(cached.getPdfBytes(), true)) {
|
try (PDDocument document = pdfDocumentFactory.load(cached.getPdfBytes(), true)) {
|
||||||
@@ -6580,7 +6582,8 @@ public class PdfJsonConversionService {
|
|||||||
log.debug(
|
log.debug(
|
||||||
"Incremental export for jobId {} resulted in no page updates; returning cached PDF",
|
"Incremental export for jobId {} resulted in no page updates; returning cached PDF",
|
||||||
jobId);
|
jobId);
|
||||||
return cached.getPdfBytes();
|
outputStream.write(cached.getPdfBytes());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
@@ -6603,7 +6606,7 @@ public class PdfJsonConversionService {
|
|||||||
"Incremental export complete for jobId {} (pages updated: {})",
|
"Incremental export complete for jobId {} (pages updated: {})",
|
||||||
jobId,
|
jobId,
|
||||||
updatedPages.stream().map(i -> i + 1).sorted().toList());
|
updatedPages.stream().map(i -> i + 1).sorted().toList());
|
||||||
return updatedBytes;
|
outputStream.write(updatedBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user