6

I have a djvu file of multiple pages. I wonder how to extract a new djvu file that consists of only a subset of multiple pages?

For example, a djvu file has 10 pages, and I would like to extract a new djvu file consisting of pages 3-6 of the original djvu file. Can it be done with some commands of djvulibre, such as djvused, djvm, ...? I am using Ubuntu Linux.

Consider two different cases: extract without removal of pages from the original djvu file, and extract without removal.

Thanks!

Peter.O
  • 32,426
  • 28
  • 115
  • 163
Tim
  • 98,580
  • 191
  • 570
  • 977

3 Answers3

7

I didn't see any way to explicitly save a range of pages, so I opted to delete the rest.

# Extract and save each page in its own file
pages=$(djvused -e 'n' "$if")
for ((i=1; i<=$pages; i++)) ;do
    of="${if%.*}.$(printf "%03d" $i).djvu"
    djvused -e "select $i; save-page-with \"$of\"" "$if"
done

# Remove one page from an existing djvu file
djvm -delete "$if" 2 # remove page 2

# Save pages 3-6 to a new file, by removing 
#   all other pages from a copy of the original
from=3; to=6
of="${if%.*}.$from-$to.djvu"
cp "$if" "$of"  
pages=$(djvused -e 'n' "$of")
for ((i=$pages; i>$to; i--)) ;do  djvm -delete "$of" $i ;done
for ((i=1;    i<$from; i++)) ;do  djvm -delete "$of" 1  ;done
Peter.O
  • 32,426
  • 28
  • 115
  • 163
  • I cannot believe that this still seems to be the way to go. But after looking around a bit, this seems to be the way. I would be happy to be shown wrong, though. – davidlowryduda Jun 23 '21 at 18:31
6

I would just use: DjVuLibre DjView 4.5 Viewer for DjVu documents. Its GUI has a Save as function under File menu and there one can save a given range of pages into djvu file.

Adobe
  • 437
  • 5
  • 13
scp
  • 61
  • 1
  • 1
  • How is djview possible to extract multiple pages from a djvu file? – Tim Jan 16 '12 at 17:34
  • 1
    it has a feature to only consider a page range in both "export" and "save as" File menu items, as specified; wonder why you didn't accept a perfectly good answer – Michael Shigorin Oct 06 '17 at 17:59
1

A simpler series of shell statements to achieve bundled DjVU splitting:

mkdir -- 'mydoc/' &&
djvmcvt -i 'mydoc.djvu' 'mydoc/' 'new-mydoc-index.djvu'
Sander
  • 151
  • 2