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, ...)
37 va_start(arglist, format);
38 vsprintf(buf, format, arglist);
45 fprintf(stderr, "system() returned %d\n", ret);
51 int args_callback_option(char*name,char*val) {
52 if (!strcmp(name, "o"))
57 else if (!strcmp(name, "v"))
62 else if (name[0]=='p')
64 /* check whether the page range follows the p directly, like
68 } while(*name == 32 || *name == 13 || *name == 10 || *name == '\t');
77 else if (!strcmp(name, "P"))
82 else if (!strcmp(name, "s"))
84 pdfswf_drawonlyshapes();
87 else if (!strcmp(name, "i"))
89 pdfswf_ignoredraworder();
92 else if (!strcmp(name, "n"))
94 pdfswf_linksopennewwindow();
97 else if (!strcmp(name, "f"))
99 pdfswf_storeallcharacters();
102 else if (!strcmp(name, "l"))
105 sprintf(buf, "%s/swfs/default_loader.swf", DATADIR);
106 preloader = strdup(buf);
109 else if (!strcmp(name, "b"))
112 sprintf(buf, "%s/swfs/default_viewer.swf", DATADIR);
113 viewer = strdup(buf);
116 else if (!strcmp(name, "L"))
124 systemf("ls %s/swfs/*_loader.swf", DATADIR);
130 else if (!strcmp(name, "B"))
138 systemf("ls %s/swfs/*_viewer.swf", DATADIR);
144 else if (name[0]=='j')
147 pdfswf_jpegquality(atoi(&name[1]));
150 pdfswf_jpegquality(atoi(val));
154 else if (!strcmp(name, "V"))
156 printf("pdf2swf - part of %s %s\n", PACKAGE, VERSION);
161 fprintf(stderr, "Unknown option: -%s\n", name);
167 struct options_t options[] =
178 {"b","defaultviewer"},
179 {"l","defaultpreloader"},
183 int args_callback_longoption(char*name,char*val) {
184 return args_long2shortoption(options, name, val);
187 int args_callback_command(char*name, char*val) {
193 fprintf(stderr, "Error: Do you want the output to go to %s or to %s?",
202 void args_callback_usage(char*name)
204 printf("Usage: %s [-si] [-j quality] [-p range] [-P password] input.pdf [output.swf]\n", name);
206 printf("-p --pages=range Convert only pages in range\n");
207 printf("-P --password=password Use password for deciphering the pdf\n");
208 printf("-s --shapes Don't use SWF Fonts, but store everything as shape\n");
209 printf("-i --ignore Ignore draw order (makes the SWF file smaller)\n");
210 printf("-j --jpegquality=quality Set quality of embedded jpeg pictures (default:85)\n");
211 printf("-v --verbose Be verbose. Use more than one -v for greater effect\n");
212 printf("-w --samewindow Don't open a new Browser Window for Links in the SWF\n");
213 printf("-f --fonts Store full fonts in SWF. (Don't reduce to used characters)\n");
214 printf("-V --version Print program version\n");
215 #ifndef SYSTEM_BACKTICKS
216 printf("The following might not work because your system call doesn't support command substitution:\n");
218 printf("-b --defaultviewer Link default viewer to the pdf (%s/swfs/default_viewer.swf)\n", DATADIR);
219 printf("-l --defaultpreloader Link preloader \"name\" to the pdf (%s/swfs/default_loader.swf)\n", DATADIR);
220 printf("-B --viewer=filename Link viewer \"name\" to the pdf (\"%s -B\" for list)\n", name);
221 printf("-L --preloader=filename Link preloader \"name\" to the pdf (\"%s -L\" for list)\n",name);
224 int main(int argn, char *argv[])
234 processargs(argn, argv);
235 initLog(0,-1,0,0,-1,loglevel);
238 fprintf(stderr, "Please use -o to specify an output file\n");
242 // test if the page range is o.k.
243 is_in_range(0x7fffffff, pagerange);
246 args_callback_usage(argv[0]);
250 logf("<verbose> reading font files from %s/fonts\n", DATADIR);
251 //TODO: use tempnam here. Check if environment already contains a
253 putenv( "T1LIB_CONFIG=/tmp/t1lib.config.tmp");
254 FILE*fi = fopen("/tmp/t1lib.config.tmp", "wb");
255 fprintf(fi, "FONTDATABASE=%s/fonts/FontDataBase\n", DATADIR);
256 fprintf(fi, "ENCODING=%s/fonts:.\n", DATADIR);
257 fprintf(fi, "AFM=%s/fonts:.\n", DATADIR);
258 fprintf(fi, "TYPE1=%s/fonts:.\n", DATADIR);
260 /* initialize t1lib */
261 T1_SetBitmapPad( 16);
262 if ((T1_InitLib(NO_LOGFILE)==NULL)){
263 fprintf(stderr, "Initialization of t1lib failed\n");
266 unlink("/tmp/t1lib.config.tmp");
268 pdfswf_init(filename, password);
269 pdfswf_setoutputfilename(outputname);
271 int pages = pdfswf_numpages();
273 for(t = 1; t <= pages; t++)
275 if(is_in_range(t, pagerange))
276 pdfswf_convertpage(t);
278 pdfswf_performconversion();
282 if(viewer || preloader) {
283 #ifndef SYSTEM_BACKTICKS
284 logf("<warning> Not sure whether system() can handle command substitution");
285 logf("<warning> (According to config.h, it can't)");
290 if(viewer && !preloader) {
291 systemf("swfcombine `swfdump -XY %s` %s viewport=%s -o %s",
292 outputname, viewer, outputname, outputname);
295 if(preloader && !viewer) {
296 logf("<warning> --preloader option without --viewer option doesn't make very much sense.");
297 ret = systemf("swfcombine `swfdump -r %s` %s/swfs/PreLoaderTemplate.swf loader=%s movie=%s -o %s",
298 preloader, DATADIR, preloader, outputname, outputname);
301 if(preloader && viewer) {
302 systemf("swfcombine %s viewport=%s -o %s",
303 viewer, outputname, outputname);
304 systemf("swfcombine `swfdump -XY %s` `swfdump -r %s` %s/swfs/PreLoaderTemplate.swf loader=%s movie=%s -o %s",
305 outputname, preloader, DATADIR, preloader, outputname, outputname);