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"
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, "V"))
61 printf("pdf2swf - part of %s %s\n", PACKAGE, VERSION);
66 fprintf(stderr, "Unknown option: -%s\n", name);
82 int args_callback_longoption(char*name,char*val) {
84 char*equal = strchr(name,'=');
89 for(t=0;t<sizeof(options)/sizeof(struct options_t);t++) {
90 if(!strcmp(options[t].longoption, name)) {
91 char*tmp = (char*)malloc(strlen(equal)+strlen(name)+2);
92 tmp[0] = options[t].shortoption;
95 strcpy(&tmp[1], equal);
97 return args_callback_option(tmp,val);
100 fprintf(stderr, "Unknown option: %s\n", name);
104 int args_callback_command(char*name, char*val) {
110 fprintf(stderr, "Error: Do you want the output to go to %s or to %s?",
119 void args_callback_usage(char*name)
121 printf("Usage: %s [-p range] [-P password] input.pdf [output.swf]\n", name);
123 printf("-p range (range) Convert only pages in range\n");
124 printf("-P password (password) Use password for deciphering the pdf\n");
128 /* check whether the value t is in a given range.
129 examples: 3 is in range 1-10: true
130 7 is in range 2-4,6,8-10: false
131 9 is in range 1,2,3-12: true
133 char is_in_range(int t, char*irange)
142 if(!irange) // no range resembles (-OO,OO)
147 while(*pos == ' ' || *pos == '\r' || *pos == '\n' || *pos == '\t')
151 while(*digits>='0' && *digits<='9')
154 fprintf(stderr, "Error: \"%s\" is not a valid format (digit expected)\n",irange);
158 tmp=*digits;*digits=0;
163 while(*pos == ' ' || *pos == '\r' || *pos == '\n' || *pos == '\t')
166 if(range && last<=t && num>=t)
178 fprintf(stderr, "Error: \"%s\" is not a valid format (too many '-'s)\n",irange);
189 /* if it isn't a '-', we assume it is a seperator like
190 ',', ';', ':', whatever. */
203 int main(int argn, char *argv[])
206 processargs(argn, argv);
207 initLog(0,-1,0,0,-1,loglevel);
209 // test if the page range is o.k.
210 is_in_range(0x7fffffff, pagerange);
213 args_callback_usage(argv[0]);
217 logf("<verbose> reading data files from %s\n", DATADIR);
218 //TODO: use tempnam here. Check if environment already contains a
220 putenv( "T1LIB_CONFIG=/tmp/t1lib.config.tmp");
221 FILE*fi = fopen("/tmp/t1lib.config.tmp", "wb");
222 fprintf(fi, "FONTDATABASE=%s/FontDataBase\n", DATADIR);
223 fprintf(fi, "ENCODING=%s:.\n", DATADIR);
224 fprintf(fi, "AFM=%s:.\n", DATADIR);
225 fprintf(fi, "TYPE1=%s:.\n", DATADIR);
227 /* initialize t1lib */
228 T1_SetBitmapPad( 16);
229 if ((T1_InitLib(NO_LOGFILE)==NULL)){
230 fprintf(stderr, "Initialization of t1lib failed\n");
233 unlink("/tmp/t1lib.config.tmp");
235 pdfswf_init(filename, password);
236 pdfswf_setoutputfilename(outputname);
238 int pages = pdfswf_numpages();
240 for(t = 1; t <= pages; t++)
242 if(is_in_range(t, pagerange))
243 pdfswf_convertpage(t);