Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ public ResponseEntity<Resource> exportPartialPdf(

validateJobAccess(jobId);

byte[] pdfBytes = pdfJsonConversionService.exportUpdatedPages(jobId, document);

String baseName =
(filename != null && !filename.isBlank())
? FILE_EXTENSION_PATTERN
Expand All @@ -197,13 +195,18 @@ public ResponseEntity<Resource> exportPartialPdf(
.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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6490,7 +6490,8 @@ public void extractPageFonts(String jobId, int pageNumber, OutputStream out)
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");
}
Expand All @@ -6513,7 +6514,8 @@ public byte[] exportUpdatedPages(String jobId, PdfJsonDocument updates) throws I
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)) {
Expand Down Expand Up @@ -6580,7 +6582,8 @@ public byte[] exportUpdatedPages(String jobId, PdfJsonDocument updates) throws I
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();
Expand All @@ -6603,7 +6606,7 @@ public byte[] exportUpdatedPages(String jobId, PdfJsonDocument updates) throws I
"Incremental export complete for jobId {} (pages updated: {})",
jobId,
updatedPages.stream().map(i -> i + 1).sorted().toList());
return updatedBytes;
outputStream.write(updatedBytes);
}
}

Expand Down
Loading