Update March 2021: Updated script + skipping pages
(adapted from lcd047's answer)
Create a backup copy of your .djvu file in case something goes wrong.
Install the numconv package from here.
Save the following as a text file e.g. generate_page_list.sh:
#!/bin/bash
## Set these parameters:
# Name first/last page $CNAME/$BCNAME? (Yes/No=0/1)
COVER=1
BCOVER=0
CNAME="C"
BCNAME="BC"
# Lowest roman page number
MINROMAN=3
# Highest roman page number
MAXROMAN=6
# Lowest arabic page number
MINARABIC=1
# Highest arabic page number
MAXARABIC=10
# Create/Empty new_page_list
> new_page_list
# Initialise total page number iTOTAL
iTOTAL=1
# Generate list of set-page-title commands
if [[ "$COVER" == 1 ]]; then
echo "select $iTOTAL; set-page-title \"$CNAME\"" >> new_page_list
((iTOTAL++))
fi
for (( i=$MINROMAN; i<=$MAXROMAN; i++)); do
iROMAN=`echo $i | numconv -f Western -t Roman_Lower`
echo "select $iTOTAL; set-page-title \"$iROMAN\"" >> new_page_list
((iTOTAL++))
done
for (( i=$MINARABIC; i<=$MAXARABIC; i++)); do
echo "select $iTOTAL; set-page-title \"$i\"" >> new_page_list
((iTOTAL++))
done
if [[ "$BCOVER" == 1 ]]; then
echo "select $iTOTAL; set-page-title \"$BCNAME\"" >> new_page_list
((iTOTAL++))
fi
Make generate_page_list.sh executable via
chmod +x generate_page_list.sh
Run the script via
./generate_page_list.sh
This produces a file new_page_list. Open this file in a text editor to check it contains a sequence of set-page-title commands like this:
select 1; set-page-title "Cover"
select 2; set-page-title "i"
select 3; set-page-title "ii"
select 4; set-page-title "iii"
select 5; set-page-title "1"
select 6; set-page-title "2"
select 7; set-page-title "3"
select 8; set-page-title "4"
select 9; set-page-title "5"
select 10; set-page-title "6"
...
Pass this list to djvused to commit the changes to your DjVu file:
djvused -f new_page_list -s file.djvu
Script with skipped pages
If your .djvu files has missing pages (e.g. empty pages left out when skanning), you can use the following extension of the above skript:
#!/bin/bash
## Set these parameters:
# Name first/last page $CNAME/$BCNAME? (Yes/No=0/1)
COVER=1
BCOVER=0
CNAME="C"
BCNAME="BC"
# Lowest roman page number
MINROMAN=3
# Highest roman page number
MAXROMAN=6
# Skipped roman page numbers
SKIPROMAN=""
# Lowest arabic page number
MINARABIC=1
# Highest arabic page number
MAXARABIC=10
# Skipped arabic page numbers
SKIPARABIC="3 5"
# Create/Empty new_page_list
> new_page_list
# Initialise total page number iTOTAL
iTOTAL=1
# Generate list of set-page-title commands
if [[ "$COVER" == 1 ]]; then
echo "select $iTOTAL; set-page-title \"$CNAME\"" >> new_page_list
((iTOTAL++))
fi
for (( i=$MINROMAN; i<=$MAXROMAN; i++)); do
if [[ ! " $SKIPROMAN " =~ " $i " ]]; then
iROMAN=`echo $i | numconv -f Western -t Roman_Lower`
echo "select $iTOTAL; set-page-title \"$iROMAN\"" >> new_page_list
((iTOTAL++))
fi
done
for (( i=$MINARABIC; i<=$MAXARABIC; i++)); do
if [[ ! " $SKIPARABIC " =~ " $i " ]]; then
echo "select $iTOTAL; set-page-title \"$i\"" >> new_page_list
((iTOTAL++))
fi
done
if [[ "$BCOVER" == 1 ]]; then
echo "select $iTOTAL; set-page-title \"$BCNAME\"" >> new_page_list
((iTOTAL++))
fi
SKIPARABIC (resp. SKIPROMAN) is a string containing a list of page numbers to be skipped, separated by spaces. You can, for example, enter numbers individually:
SKIPARABIC="3 4"
or as a range
SKIPARABIC="{3..5}"
or a combination of one or more numbers and ranges (again separated by spaces
SKIPARABIC="{3..5} 7 {9..15}"
I am using string comparison (according to this stackoverflow answer), which may not be the most efficient, but it was the easiest and most readable solution I could find for skipping iterations in a loop according to a list.