2 main routine for pdf2swf(1)
4 Part of the swftools package.
6 Copyright (c) 2001,2002,2003 Matthias Kramm <kramm@quiss.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
27 #include "../../swftools/config.h"
28 #include "../../swftools/lib/args.h"
29 #include "../../swftools/lib/os.h"
30 #include "../../swftools/lib/gfxsource.h"
31 #include "../../swftools/lib/gfxdevice.h"
32 #include "../../swftools/lib/gfxpoly.h"
33 #include "../../swftools/lib/devices/bbox.h"
34 #include "../../swftools/lib/devices/lrf.h"
35 #include "../../swftools/lib/devices/ocr.h"
36 #include "../../swftools/lib/devices/rescale.h"
37 #include "../../swftools/lib/devices/record.h"
38 #include "../../swftools/lib/readers/image.h"
39 #include "../../swftools/lib/readers/swf.h"
40 #include "../../swftools/lib/pdf/pdf.h"
41 #include "../../swftools/lib/log.h"
45 static char * outputname = 0;
46 static int loglevel = 3;
47 static char * pagerange = 0;
48 static char * filename = 0;
50 int args_callback_option(char*name,char*val) {
51 if (!strcmp(name, "o"))
56 else if (!strcmp(name, "v"))
59 setConsoleLogging(loglevel);
62 else if (!strcmp(name, "q"))
65 setConsoleLogging(loglevel);
68 else if (name[0]=='p')
72 } while(*name == 32 || *name == 13 || *name == 10 || *name == '\t');
81 else if (!strcmp(name, "s"))
83 const char*s = strdup(val);
84 char*c = strchr(s, '=');
88 driver->set_parameter(driver, s,c);
91 driver->set_parameter(driver, s,"1");
94 else if (!strcmp(name, "V"))
96 printf("pdf2swf - part of %s %s\n", PACKAGE, VERSION);
101 fprintf(stderr, "Unknown option: -%s\n", name);
107 struct options_t options[] =
116 int args_callback_longoption(char*name,char*val) {
117 return args_long2shortoption(options, name, val);
120 int args_callback_command(char*name, char*val) {
126 fprintf(stderr, "Error: Do you want the output to go to %s or to %s?",
135 void args_callback_usage(char*name)
139 int main(int argn, char *argv[])
141 processargs(argn, argv);
142 initLog(0,-1,0,0,-1,loglevel);
144 gfxsource_t*source = 0;
147 fprintf(stderr, "Please specify an input file\n");
151 if(strstr(filename, ".pdf") || strstr(filename, ".PDF")) {
152 msg("<notice> Treating file as PDF");
153 source = gfxsource_pdf_create();
154 } else if(strstr(filename, ".swf") || strstr(filename, ".SWF")) {
155 msg("<notice> Treating file as SWF");
156 source = gfxsource_swf_create();
157 } else if(strstr(filename, ".jpg") || strstr(filename, ".JPG") ||
158 strstr(filename, ".png") || strstr(filename, ".PNG")) {
159 msg("<notice> Treating file as Image");
160 source = gfxsource_image_create();
166 outputname = stripFilename(filename, ".out");
167 msg("<notice> Output filename not given. Writing to %s", outputname);
172 fprintf(stderr, "Please use -o to specify an output file\n");
175 printf("%s\n", filename);
176 is_in_range(0x7fffffff, pagerange);
178 source->set_parameter(source, "pages", pagerange);
181 args_callback_usage(argv[0]);
185 gfxdocument_t* doc = source->open(source, filename);
187 msg("<error> Couldn't open %s", filename);
192 gfxdevice_lrf_init(&lrf);
195 gfxdevice_rescale_init(&rescale, &lrf, 592, 732, 0);
197 gfxdevice_t*out = &rescale;
198 out->setparameter(out, "keepratio", "1");
199 out->setparameter(out, "pagepattern", outputname);
201 gfxdevice_t bbox2,*bbox=&bbox2;
202 gfxdevice_bbox_init(bbox);
203 bbox->setparameter(bbox, "graphics", "0");
207 for(pagenr = 1; pagenr <= doc->num_pages; pagenr++)
209 if(is_in_range(pagenr, pagerange)) {
210 gfxpage_t* page = doc->getpage(doc, pagenr);
211 bbox->startpage(bbox,-1,-1);
212 page->render(page, bbox);
213 gfxbbox_t b = gfxdevice_bbox_getbbox(bbox);
215 out->startpage(out, b.xmax-b.xmin, b.ymax-b.ymin);
216 page->rendersection(page, out, -b.xmin, -b.ymin, 0,0,b.xmax-b.xmin,b.ymax-b.ymin);
223 gfxresult_t*result = out->finish(out);
226 if(result->save(result, outputname) < 0) {
229 result->destroy(result);