2 main routine for pdf2swf(1)
4 Part of the swftools package.
6 Copyright (c) 2001 Matthias Kramm <kramm@quiss.org>
8 This file is distributed under the GPL, see file COPYING for details */
15 #include "../config.h"
16 #include "../lib/args.h"
23 static char * outputname = 0;
24 static int loglevel = 3;
25 static char * pagerange = 0;
26 static char * filename = 0;
27 static char * password = 0;
29 static char * preloader = 0;
30 static char * viewer = 0;
32 int systemf(const char* format, ...)
36 va_start(arglist, format);
37 vsprintf(buf, format, arglist);
45 int args_callback_option(char*name,char*val) {
46 if (!strcmp(name, "o"))
51 else if (!strcmp(name, "v"))
56 else if (name[0]=='p')
58 /* check whether the page range follows the p directly, like
62 } while(*name == 32 || *name == 13 || *name == 10 || *name == '\t');
71 else if (!strcmp(name, "P"))
76 else if (!strcmp(name, "s"))
78 pdfswf_drawonlyshapes();
81 else if (!strcmp(name, "i"))
83 pdfswf_ignoredraworder();
86 else if (!strcmp(name, "n"))
88 pdfswf_linksopennewwindow();
91 else if (!strcmp(name, "f"))
93 pdfswf_storeallcharacters();
96 else if (!strcmp(name, "l"))
104 systemf("ls %s/swfs/*_loader.swf", DATADIR);
110 else if (!strcmp(name, "b"))
118 systemf("ls %s/swfs/*_viewer.swf", DATADIR);
124 else if (name[0]=='j')
127 pdfswf_jpegquality(atoi(&name[1]));
130 pdfswf_jpegquality(atoi(val));
134 else if (!strcmp(name, "V"))
136 printf("pdf2swf - part of %s %s\n", PACKAGE, VERSION);
141 fprintf(stderr, "Unknown option: -%s\n", name);
147 struct options_t options[] =
161 int args_callback_longoption(char*name,char*val) {
162 return args_long2shortoption(options, name, val);
165 int args_callback_command(char*name, char*val) {
171 fprintf(stderr, "Error: Do you want the output to go to %s or to %s?",
180 void args_callback_usage(char*name)
182 printf("Usage: %s [-si] [-j quality] [-p range] [-P password] input.pdf [output.swf]\n", name);
184 printf("-p --pages=range Convert only pages in range\n");
185 printf("-P --password=password Use password for deciphering the pdf\n");
186 printf("-s --shapes Don't use SWF Fonts, but store everything as shape\n");
187 printf("-i --ignore Ignore draw order (makes the SWF file smaller)\n");
188 printf("-j --jpegquality=quality Set quality of embedded jpeg pictures (default:85)\n");
189 printf("-v --verbose Be verbose. Use more than one -v for greater effect\n");
190 printf("-w --samewindow Don't open a new Browser Window for Links in the SWF\n");
191 printf("-f --fonts Store full fonts in SWF. (Don't reduce to used characters)\n");
192 printf("-b --viewer name Link viewer \"name\" to the pdf (\"%s -b\" for list)\n");
193 printf("-l --preloader name Link preloader \"name\" to the pdf (\"%s -l\" for list)\n");
194 printf("-V --version Print program version\n");
197 int main(int argn, char *argv[])
206 processargs(argn, argv);
207 initLog(0,-1,0,0,-1,loglevel);
210 fprintf(stderr, "Please use -o to specify an output file\n");
214 // test if the page range is o.k.
215 is_in_range(0x7fffffff, pagerange);
218 args_callback_usage(argv[0]);
222 logf("<verbose> reading data files from %s\n", DATADIR);
223 //TODO: use tempnam here. Check if environment already contains a
225 putenv( "T1LIB_CONFIG=/tmp/t1lib.config.tmp");
226 FILE*fi = fopen("/tmp/t1lib.config.tmp", "wb");
227 fprintf(fi, "FONTDATABASE=%s/fonts/FontDataBase\n", DATADIR);
228 fprintf(fi, "ENCODING=%s/fonts:.\n", DATADIR);
229 fprintf(fi, "AFM=%s/fonts:.\n", DATADIR);
230 fprintf(fi, "TYPE1=%s/fonts:.\n", DATADIR);
232 /* initialize t1lib */
233 T1_SetBitmapPad( 16);
234 if ((T1_InitLib(NO_LOGFILE)==NULL)){
235 fprintf(stderr, "Initialization of t1lib failed\n");
238 unlink("/tmp/t1lib.config.tmp");
240 pdfswf_init(filename, password);
241 pdfswf_setoutputfilename(outputname);
243 int pages = pdfswf_numpages();
245 for(t = 1; t <= pages; t++)
247 if(is_in_range(t, pagerange))
248 pdfswf_convertpage(t);
250 pdfswf_performconversion();
254 if(!viewer && preloader)
255 logf("<warning> --preloader option without --viewer option doesn't make very much sense.");
256 if(viewer || preloader)
260 systemf("swfcombine `swfdump -XY %s` %s viewport=%s -o %s",
261 outputname, viewer, outputname, outputname);
265 systemf("swfcombine `swfdump -r %s` %s/swfs/PreLoaderTemplate.swf loader=%s movie=%s -o %s",
266 preloader, DATADIR, preloader, outputname, outputname);