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 (!strcmp(name, "f"))
76 pdfswf_storeallcharacters();
79 else if (name[0]=='j')
82 pdfswf_jpegquality(atoi(&name[1]));
85 pdfswf_jpegquality(atoi(val));
89 else if (!strcmp(name, "V"))
91 printf("pdf2swf - part of %s %s\n", PACKAGE, VERSION);
96 fprintf(stderr, "Unknown option: -%s\n", name);
102 struct options_t options[] =
114 int args_callback_longoption(char*name,char*val) {
115 return args_long2shortoption(options, name, val);
118 int args_callback_command(char*name, char*val) {
124 fprintf(stderr, "Error: Do you want the output to go to %s or to %s?",
133 void args_callback_usage(char*name)
135 printf("Usage: %s [-si] [-j quality] [-p range] [-P password] input.pdf [output.swf]\n", name);
137 printf("-p --pages=range Convert only pages in range\n");
138 printf("-P --password=password Use password for deciphering the pdf\n");
139 printf("-s --shapes Don't use SWF Fonts, but store everything as shape\n");
140 printf("-i --ignore Ignore draw order (makes the SWF file smaller)\n");
141 printf("-j --jpegquality=quality Set quality of embedded jpeg pictures (default:85)\n");
142 printf("-v --verbose Be verbose. Use more than one -v for greater effect\n");
143 printf("-w --samewindow Don't open a new Browser Window for Links in the SWF\n");
144 printf("-f --fonts Store full fonts in SWF. (Don't reduce to used characters)\n");
145 printf("-V --version Print program version\n");
148 int main(int argn, char *argv[])
151 processargs(argn, argv);
152 initLog(0,-1,0,0,-1,loglevel);
155 fprintf(stderr, "Please use -o to specify an output file\n");
159 // test if the page range is o.k.
160 is_in_range(0x7fffffff, pagerange);
163 args_callback_usage(argv[0]);
167 logf("<verbose> reading data files from %s\n", DATADIR);
168 //TODO: use tempnam here. Check if environment already contains a
170 putenv( "T1LIB_CONFIG=/tmp/t1lib.config.tmp");
171 FILE*fi = fopen("/tmp/t1lib.config.tmp", "wb");
172 fprintf(fi, "FONTDATABASE=%s/FontDataBase\n", DATADIR);
173 fprintf(fi, "ENCODING=%s:.\n", DATADIR);
174 fprintf(fi, "AFM=%s:.\n", DATADIR);
175 fprintf(fi, "TYPE1=%s:.\n", DATADIR);
177 /* initialize t1lib */
178 T1_SetBitmapPad( 16);
179 if ((T1_InitLib(NO_LOGFILE)==NULL)){
180 fprintf(stderr, "Initialization of t1lib failed\n");
183 unlink("/tmp/t1lib.config.tmp");
185 pdfswf_init(filename, password);
186 pdfswf_setoutputfilename(outputname);
188 int pages = pdfswf_numpages();
190 for(t = 1; t <= pages; t++)
192 if(is_in_range(t, pagerange))
193 pdfswf_convertpage(t);
195 pdfswf_performconversion();