Skip to content

Commit

Permalink
fixed downloading of page range pdf and of config files
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Alpers committed Jan 23, 2025
1 parent 72b8d54 commit ac207b6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3754,17 +3754,21 @@ public void generatePageRangePdf() {
String filename = String.format("%s_%s_%s.pdf", this.pi, this.firstPdfPage, this.lastPdfPage);
try (PipedInputStream in = new PipedInputStream(); OutputStream out = new PipedOutputStream(in);
ExecutorService executor = Executors.newFixedThreadPool(1)) {
String firstPageName =
Optional.ofNullable(this.firstPdfPage).flatMap(this::getPage).map(PhysicalElement::getFileName).orElse(null);
String lastPageName =
Optional.ofNullable(this.lastPdfPage).flatMap(this::getPage).map(PhysicalElement::getFileName).orElse(null);

SinglePdfRequest request = new SinglePdfRequest(Map.of(
"imageSource", DataFileTools.getMediaFolder(this.pi).toAbsolutePath().toString(),
"pdfSource", DataFileTools.getPdfFolder(this.pi).toAbsolutePath().toString(),
"altoSource", DataFileTools.getAltoFolder(this.pi).toAbsolutePath().toString(),
"first", firstPageName,
"last", lastPageName));

Map<String, String> params = new HashMap<>();
params.put("imageSource", DataFileTools.getMediaFolder(this.pi).toAbsolutePath().toString());
params.put("pdfSource", DataFileTools.getPdfFolder(this.pi).toAbsolutePath().toString());
params.put("altoSource", DataFileTools.getAltoFolder(this.pi).toAbsolutePath().toString());
Optional.ofNullable(this.firstPdfPage)
.flatMap(this::getPage)
.map(PhysicalElement::getFileName)
.ifPresent(first -> params.put("first", first));
Optional.ofNullable(this.lastPdfPage)
.flatMap(this::getPage)
.map(PhysicalElement::getFileName)
.ifPresent(last -> params.put("last", last));

SinglePdfRequest request = new SinglePdfRequest(params);
executor.submit(() -> {
try {
new GetPdfAction().writePdf(request, ContentServerConfiguration.getInstance(), out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@

<div class="admin__config-editor-file-selection-single-entry-action-download">
<!-- TODO This seems to cause an IllegalStateException in OmniFaces when used with JSF4 -->
<!-- <a jsf:action="#{adminConfigEditorBean.download(record.file)}" data-toggle="tooltip" data-trigger="hover" data-placement="top" title="#{msg.downloadHeading}"><i class="fa fa-download"></i> -->
<!-- </a> -->
<button jsf:action="#{adminConfigEditorBean.download(record.file)}" data-toggle="tooltip" data-trigger="hover" data-placement="top" title="#{msg.downloadHeading}"><i class="fa fa-download"></i>
</button>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@
</div>
</div>

<a
<button
jsf:action="#{activeDocumentBean.viewManager.generatePageRangePdf()}"
id="pdfPageRangeLink"
class="badge badge-dark widget-downloads__page-download-pdf-range widget-downloads__page-range-pdf-link"
Expand All @@ -557,7 +557,7 @@
aria-label="#{msg.image}: #{msg.label__pdf_download}">
<i class="fa fa-file-pdf-o" aria-hidden="true"></i>
#{msg.downloadButton}
</a>
</button>
</h:form>

</div>
Expand Down

0 comments on commit ac207b6

Please sign in to comment.