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 */
14 #include "../config.h"
15 #include "../lib/args.h"
22 static char * outputname = 0;
23 static int loglevel = 3;
24 static char * pagerange = 0;
25 static char * filename = 0;
26 static char * password = 0;
28 int args_callback_option(char*name,char*val) {
29 if (!strcmp(name, "o"))
34 else if (!strcmp(name, "v"))
39 else if (name[0]=='p')
41 /* check whether the page range follows the p directly, like
45 } while(*name == 32 || *name == 13 || *name == 10 || *name == '\t');
54 else if (!strcmp(name, "P"))
59 else if (!strcmp(name, "s"))
61 pdfswf_drawonlyshapes();
64 else if (!strcmp(name, "i"))
66 pdfswf_ignoredraworder();
69 else if (!strcmp(name, "n"))
71 pdfswf_linksopennewwindow();
74 else if (name[0]=='j')
77 pdfswf_jpegquality(atoi(&name[1]));
80 pdfswf_jpegquality(atoi(val));
84 else if (!strcmp(name, "V"))
86 printf("pdf2swf - part of %s %s\n", PACKAGE, VERSION);
91 fprintf(stderr, "Unknown option: -%s\n", name);
97 struct options_t options[] =
108 int args_callback_longoption(char*name,char*val) {
109 return args_long2shortoption(options, name, val);
112 int args_callback_command(char*name, char*val) {
118 fprintf(stderr, "Error: Do you want the output to go to %s or to %s?",
127 void args_callback_usage(char*name)
129 printf("Usage: %s [-si] [-j quality] [-p range] [-P password] input.pdf [output.swf]\n", name);
131 printf("-p --pages=range Convert only pages in range\n");
132 printf("-P --password=password Use password for deciphering the pdf\n");
133 printf("-s --shapes Don't use SWF Fonts, but store everything as shape\n");
134 printf("-i --ignore Ignore draw order (makes the SWF file smaller)\n");
135 printf("-j --jpegquality=quality Set quality of embedded jpeg pictures (default:85)\n");
136 printf("-v --verbose Be verbose. Use more than one -v for greater effect\n");
137 printf("-w --samewindow Don't open a new Browser Window for Links in the SWF\n");
138 printf("-V --version Print program version\n");
141 /* check whether the value t is in a given range.
142 examples: 3 is in range 1-10: true
143 7 is in range 2-4,6,8-10: false
144 9 is in range 1,2,3-12: true
146 char is_in_range(int t, char*irange)
155 if(!irange) // no range resembles (-OO,OO)
160 while(*pos == ' ' || *pos == '\r' || *pos == '\n' || *pos == '\t')
164 while(*digits>='0' && *digits<='9')
167 fprintf(stderr, "Error: \"%s\" is not a valid format (digit expected)\n",irange);
171 tmp=*digits;*digits=0;
176 while(*pos == ' ' || *pos == '\r' || *pos == '\n' || *pos == '\t')
179 if(range && last<=t && num>=t)
191 fprintf(stderr, "Error: \"%s\" is not a valid format (too many '-'s)\n",irange);
202 /* if it isn't a '-', we assume it is a seperator like
203 ',', ';', ':', whatever. */
216 int main(int argn, char *argv[])
219 processargs(argn, argv);
220 initLog(0,-1,0,0,-1,loglevel);
223 fprintf(stderr, "Please use -o to specify an output file\n");
227 // test if the page range is o.k.
228 is_in_range(0x7fffffff, pagerange);
231 args_callback_usage(argv[0]);
235 logf("<verbose> reading data files from %s\n", DATADIR);
236 //TODO: use tempnam here. Check if environment already contains a
238 putenv( "T1LIB_CONFIG=/tmp/t1lib.config.tmp");
239 FILE*fi = fopen("/tmp/t1lib.config.tmp", "wb");
240 fprintf(fi, "FONTDATABASE=%s/FontDataBase\n", DATADIR);
241 fprintf(fi, "ENCODING=%s:.\n", DATADIR);
242 fprintf(fi, "AFM=%s:.\n", DATADIR);
243 fprintf(fi, "TYPE1=%s:.\n", DATADIR);
245 /* initialize t1lib */
246 T1_SetBitmapPad( 16);
247 if ((T1_InitLib(NO_LOGFILE)==NULL)){
248 fprintf(stderr, "Initialization of t1lib failed\n");
251 unlink("/tmp/t1lib.config.tmp");
253 pdfswf_init(filename, password);
254 pdfswf_setoutputfilename(outputname);
256 int pages = pdfswf_numpages();
258 for(t = 1; t <= pages; t++)
260 if(is_in_range(t, pagerange))
261 pdfswf_convertpage(t);
263 pdfswf_performconversion();