2
//C- -------------------------------------------------------------------
4
//C- Copyright (c) 2002 Leon Bottou and Yann Le Cun.
5
//C- Copyright (c) 2001 AT&T
7
//C- This software is subject to, and may be distributed under, the
8
//C- GNU General Public License, either Version 2 of the license,
9
//C- or (at your option) any later version. The license should have
10
//C- accompanied the software or you may obtain a copy of the license
11
//C- from the Free Software Foundation at http://www.fsf.org .
13
//C- This program is distributed in the hope that it will be useful,
14
//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
//C- GNU General Public License for more details.
18
//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library from
19
//C- Lizardtech Software. Lizardtech Software has authorized us to
20
//C- replace the original DjVu(r) Reference Library notice by the following
21
//C- text (see doc/lizard2002.djvu and doc/lizardtech2007.djvu):
23
//C- ------------------------------------------------------------------
24
//C- | DjVu (r) Reference Library (v. 3.5)
25
//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
26
//C- | The DjVu Reference Library is protected by U.S. Pat. No.
27
//C- | 6,058,214 and patents pending.
29
//C- | This software is subject to, and may be distributed under, the
30
//C- | GNU General Public License, either Version 2 of the license,
31
//C- | or (at your option) any later version. The license should have
32
//C- | accompanied the software or you may obtain a copy of the license
33
//C- | from the Free Software Foundation at http://www.fsf.org .
35
//C- | The computer code originally released by LizardTech under this
36
//C- | license and unmodified by other parties is deemed "the LIZARDTECH
37
//C- | ORIGINAL CODE." Subject to any third party intellectual property
38
//C- | claims, LizardTech grants recipient a worldwide, royalty-free,
39
//C- | non-exclusive license to make, use, sell, or otherwise dispose of
40
//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the
41
//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU
42
//C- | General Public License. This grant only confers the right to
43
//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to
44
//C- | the extent such infringement is reasonably necessary to enable
45
//C- | recipient to make, have made, practice, sell, or otherwise dispose
46
//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to
47
//C- | any greater extent that may be necessary to utilize further
48
//C- | modifications or combinations.
50
//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
51
//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
52
//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
53
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
54
//C- +------------------------------------------------------------------
60
# pragma implementation
67
djvm [options] <djvu_doc_name> [djvufiles] [pagenum]
71
File #"djvm.cpp"# and program #djvm# illustrate how class \Ref{DjVuDocEditor}
72
can be used to create and modify DjVu multipage documents. The program
73
demonstrates how to pack several DjVu single-page files together,
74
how to remove pages from a multipage document or how to insert new.
77
Depending on the task to be performed, the number and types of arguments
80
\item To create a new document
82
#djvm -c[reate] <doc.djvu> <page_1.djvu> ... <page_n.djvu>#
84
This will package pages represented by files #<page_1.djvu>#
85
... #<page_n.djvu># into #BUNDLED# multipage DjVu document
86
#<doc.djvu># (see \Ref{DjVuDocument} for the explanation of
87
the #BUNDLED# format). The specified page files may include other
88
files (by means of #INCL# chunks). They will also be packed
91
\item To insert a page
93
#djvm -i[nsert] <doc.djvu> <page.djvu> [<page_num>]#
95
This will insert page represented by file #<page.djvu># into
96
document #<doc.djvu># as page number #<page_num># (page
97
numbering starts from #1#). Negative or missing #<page_num>#
98
means to append the page.
100
The #<page.djvu># file can actually be another
101
multipage DjVu document. In this cases, all pages from that
102
document will be inserted into #<doc.djvu># starting from
105
\item To delete a page
107
#djvm -d[elete] <doc.djvu> <page_num>#
109
This will remove page number #<page_num># from document
110
#<doc.djvu>#. If there is only one page left in #<doc.djvu>#
111
after deletion, it will automatically be converted to a
112
single page DjVu file format. Page numbering starts from #1#.
114
\item To view document contents
116
#djvm -l[ist] <doc.djvu>#
118
This will list all files composing the given document #<doc.djvu>#.
119
The files list includes the names of page files plus names
120
of any files included into the page files by means of
125
DjVu multipage documents creator.
127
Andrei Erofeev <eaf@geocities.com>
132
#include "GException.h"
133
#include "DjVuDocEditor.h"
135
#include "DjVuMessage.h"
142
static const char * progname;
148
#ifdef DJVULIBRE_VERSION
149
"DJVM --- DjVuLibre-" DJVULIBRE_VERSION "\n"
151
"DjVu multipage document manipulation utility\n"
154
" To compose a multipage document:\n"
155
" %s -c[reate] <doc.djvu> <page_1.djvu> ... <page_n.djvu>\n"
156
" where <doc.djvu> is the name of the BUNDLED document to be\n"
157
" created, <page_n.djvu> are the names of the page files to\n"
158
" be packed together.\n"
160
" To insert a new page into an existing document:\n"
161
" %s -i[nsert] <doc.djvu> <page.djvu> [<page_num>]\n"
162
" where <doc.djvu> is the name of the BUNDLED DjVu document to be\n"
163
" modified, <page.djvu> is the name of the single-page DjVu document\n"
164
" file to be inserted as page <page_num> (page numbers start from 1).\n"
165
" Negative or omitted <page_num> means to append the page.\n"
166
" <page.djvu> can be another multipage DjVu document, in which case\n"
167
" all pages of that document will be inserted into <doc.djvu>\n"
168
" starting starting at page <page_num>\n"
170
" To delete a page from an existing document:\n"
171
" %s -d[elete] <doc.djvu> <page_num>\n"
172
" where <doc.djvu> is the name of the docyment to be modified\n"
173
" and <page_num> is the number of the page to be deleted\n"
175
" To list document contents:\n"
176
" %s -l[ist] <doc.djvu>\n"
178
"Pages being inserted may reference other files by means of INCL chunks.\n"
179
"Moreover, files shared between pages will be stored into the document\n"
181
"\n", progname, progname, progname, progname );
185
create(GArray<GUTF8String> &argv)
186
// djvm -c[reate] <doc.djvu> <page_1.djvu> ... <page_n.djvu>
187
// doc.djvu will be overwritten
189
const int argc=argv.hbound()+1;
190
if (argc<4) { usage(); exit(1); }
192
// Initialize the DjVuDocEditor class
193
GP<DjVuDocEditor> doc=DjVuDocEditor::create_wait();
197
for(int i=3;i<argc;i++)
198
list.append(GURL::Filename::UTF8(argv[i]));
199
doc->insert_group(list);
201
const GURL::Filename::UTF8 url(argv[2]);
202
// Save in BUNDLED format
203
doc->save_as(url, true);
207
insert(GArray<GUTF8String> &argv)
208
// djvm -i[nsert] <doc.djvu> <page.djvu> <page_num>
210
const int argc=argv.hbound()+1;
211
if (argc!=4 && argc!=5) { usage(); exit(1); }
213
// Initialize DjVuDocEditor class
214
const GURL::Filename::UTF8 url(argv[2]);
215
GP<DjVuDocEditor> doc=DjVuDocEditor::create_wait(url);
219
if (argc==5) page_num=atoi(argv[4])-1;
220
doc->insert_page(GURL::Filename::UTF8(argv[3]), page_num);
227
del(GArray<GUTF8String> &argv)
228
// djvm -d[elete] <doc.djvu> <page_num>
230
const int argc=argv.hbound()+1;
231
if (argc!=4) { usage(); exit(1); }
233
// Initialize DjVuDocEditor class
234
const GURL::Filename::UTF8 url(argv[2]);
235
GP<DjVuDocEditor> doc=DjVuDocEditor::create_wait(url);
238
int page_num=atoi(argv[3])-1;
241
DjVuPrintErrorUTF8("%s","Page number must be positive.\n");
244
doc->remove_page(page_num);
251
list(GArray<GUTF8String> &argv)
252
// djvm -l[ist] <doc.djvu>
254
const int argc=argv.hbound()+1;
255
if (argc!=3) { usage(); exit(1); }
257
const GURL::Filename::UTF8 url(argv[2]);
258
GP<DjVmDoc> doc=DjVmDoc::create();
261
GP<DjVmDir> dir=doc->get_djvm_dir();
264
GPList<DjVmDir::File> files_list=dir->get_files_list();
265
printf("Size Type Name\n");
266
printf("--------------------------\n");
267
for(GPosition pos=files_list;pos;++pos)
269
GP<DjVmDir::File> file=files_list[pos];
270
printf("%6d ", file->size);
274
sprintf(buffer, "PAGE #%d", file->get_page_num()+1);
275
printf("%s", buffer);
276
for(int i=strlen(buffer);i<9;i++)
278
} else if (file->is_include())
280
printf("%s", "INCLUDE ");
281
} else if (file->is_shared_anno())
283
printf("%s", "SHARED_ANNO ");
284
}else if (file->is_thumbnails())
286
printf("%s", "THUMBNAIL");
289
printf("%s", "UNKNOWN ");
291
printf(" %s\n", (const char *) file->get_save_name());
297
main(int argc, char ** argv)
299
setlocale(LC_ALL,"");
300
setlocale(LC_NUMERIC,"C");
301
djvu_programname(argv[0]);
302
GArray<GUTF8String> dargv(0,argc-1);
303
for(int i=0;i<argc;++i)
304
dargv[i]=GNativeString(argv[i]);
305
progname=dargv[0]=GOS::basename(dargv[0]);
308
if (argc<2) { usage(); exit(1); }
309
if (!dargv[1].cmp("-c", 2)) create(dargv);
310
else if (!dargv[1].cmp("-i", 2)) insert(dargv);
311
else if (!dargv[1].cmp("-d", 2)) del(dargv);
312
else if (!dargv[1].cmp("-l", 2)) list(dargv);
313
else { usage(); exit(1); }