Skip to content

Commit

Permalink
Set FILES to ensure proper order
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed Nov 6, 2024
1 parent 20c09d8 commit 07b1b91
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions examples/mergepdf/cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ MAX_THREADS=7
PIDS=()

# iterate over all images in the IIIF manifest
curl -s "$1/book-manifest" | jq -r '.sequences[0].canvases[].images[0].resource."@id"' | while read -r URL; do
URLS=$(curl -s "$1/book-manifest" | jq -r '.sequences[0].canvases[].images[0].resource."@id"')
while read -r URL; do
# If we have reached the max thread limit, wait for any one job to finish
if [ "${#PIDS[@]}" -ge "$MAX_THREADS" ]; then
wait -n
Expand All @@ -24,6 +25,11 @@ curl -s "$1/book-manifest" | jq -r '.sequences[0].canvases[].images[0].resource.
) &
PIDS+=("$!")
I="$(( I + 1))"
done <<< "$URLS"

FILES=()
for index in $(seq 0 $((I - 1))); do
FILES+=("$TMP_DIR/img_${index}.pdf")
done

wait
Expand All @@ -32,7 +38,6 @@ wait
TITLE=$(curl -L "$1?_format=json" | jq -r '.title[0].value')
echo "[ /Title ($TITLE)/DOCINFO pdfmark" > "$TMP_DIR/metadata.txt"

mapfile -t FILES < <(ls -rt "$TMP_DIR"/img_*.pdf)
gs -dBATCH \
-dNOPAUSE \
-dQUIET \
Expand Down

0 comments on commit 07b1b91

Please sign in to comment.