#include <sys/stat.h>
#endif
#include "../lib/args.h"
+#include "../lib/os.h"
#include "SWFOutputDev.h"
#include "log.h"
-#ifndef WIN32
-#define FONTDIR SWFTOOLS_DATADIR "/fonts"
-#define SWFDIR SWFTOOLS_DATADIR "/swfs"
-#else
-#define FONTDIR "C:\\swftools\\fonts"
-#define SWFDIR "C:\\swftools\\swfs"
-#endif
+#define FONTDIR concatPaths(getInstallationPath(), "fonts")
+#define SWFDIR concatPaths(getInstallationPath(), "swfs")
static char * outputname = 0;
static int loglevel = 3;
static char * pagerange = 0;
static char * filename = 0;
static char * password = 0;
+static int zlib = 0;
static char * preloader = 0;
static char * viewer = 0;
else if (!strcmp(name, "z"))
{
pdfswf_setparameter("enablezlib", "1");
+ zlib = 1;
return 0;
}
else if (!strcmp(name, "n"))
pdfswf_setparameter("storeallcharacters", "1");
return 0;
}
+ else if (!strcmp(name, "w"))
+ {
+ pdfswf_setparameter("linksopennewwindow", "0");
+ return 0;
+ }
else if (!strcmp(name, "F"))
{
char *s = strdup(val);
" graphic errors)\n");
printf("-s filloverlap Make intersecting shapes overlap, instead of canceling each\n"
" other out. (Needed for some Powerpoint PDFs)\n");
- printf("-2 Put 2 pages into each frame.\n");
- printf("-4 Put 4 pages into each frame.\n");
+ //deliberately undocumented (for now)
+ //printf("-2 Put 2 pages into each frame.\n");
+ //printf("-4 Put 4 pages into each frame.\n");
printf("Postprocessing options:\n");
#ifndef SYSTEM_BACKTICKS
printf("(They might not work because your system call doesn't support command substitution)\n");
#endif
- printf("-b --defaultviewer Link default viewer to the pdf (%s/swfs/default_viewer.swf)\n", SWFTOOLS_DATADIR);
- printf("-l --defaultpreloader Link default preloader the pdf (%s/swfs/default_loader.swf)\n", SWFTOOLS_DATADIR);
+ printf("-b --defaultviewer Link default viewer to the pdf (%s)\n", concatPaths(SWFDIR, "default_viewer.swf"));
+ printf("-l --defaultpreloader Link default preloader the pdf (%s)\n", concatPaths(SWFDIR, "default_loader.swf"));
printf("-B --viewer=filename Link viewer \"name\" to the pdf (\"%s -B\" for list)\n", name);
printf("-L --preloader=filename Link preloader \"name\" to the pdf (\"%s -L\" for list)\n",name);
}
-static char* stripfilename(char*filename, char*newext)
-{
- char*last1 = strrchr(filename, '/');
- char*last2 = strrchr(filename, '\\');
- char*pos = filename;
- char*name;
- char*dot;
- if(last1>pos) pos = last1 + 1;
- if(last2>pos) pos = last2 + 1;
- name = (char*)malloc(strlen(pos)+5);
- strcpy(name, pos);
- dot = strrchr(name, '.');
- if(dot) {
- *dot = 0;
- }
- strcat(name, newext);
- return name;
-}
-
int main(int argn, char *argv[])
{
int ret;
initLog(0,-1,0,0,-1,loglevel);
#if defined(WIN32) && defined(HAVE_STAT) && defined(HAVE_SYS_STAT_H)
- FILE*test = fopen(FONTDIR "\\d050000l.afm", "rb");
+ FILE*test = fopen(concatPaths(FONTDIR,"\\d050000l.afm"), "rb");
if(!test) {
- fprintf(stderr, "Couldn't find file " FONTDIR "\\d050000l.afm- pdf2swf not installed properly? OS says:\n");
+ fprintf(stderr, "Couldn't find file %s - pdf2swf not installed properly? OS says:\n", concatPaths(FONTDIR, "\\d050000l.afm"));
perror("open");
exit(1);
}
if(!outputname)
{
if(filename) {
- outputname = stripfilename(filename, ".swf");
+ outputname = stripFilename(filename, ".swf");
msg("<notice> Output filename not given. Writing to %s", outputname);
}
}
}
nup_pos++;
}
- if(!swf_output_save(swf, outputname))
+ if(swf_output_save(swf, outputname) < 0) {
exit(1);
+ }
+ msg("<notice> SWF written");
swf_output_destroy(swf);
pdf_destroy(pdf);
printf("\n");
}
+ char*zip = "";
+ if(zlib)
+ zip = "-z";
+
if(viewer && !preloader) {
- systemf("swfcombine `swfdump -XY \"%s\"` \"%s\" viewport=\"%s\" -o \"%s\"",
+ systemf("swfcombine %s `swfdump -XY \"%s\"` \"%s\" viewport=\"%s\" -o \"%s\"",zip,
outputname, viewer, outputname, outputname);
if(!system_quiet)
printf("\n");
}
if(preloader && !viewer) {
msg("<warning> --preloader option without --viewer option doesn't make very much sense.");
- ret = systemf("swfcombine `swfdump -r \"%s\"` %s/PreLoaderTemplate.swf loader=\"%s\" movie=\"%s\" -o \"%s\"",
+ ret = systemf("swfcombine %s `swfdump -r \"%s\"` %s/PreLoaderTemplate.swf loader=\"%s\" movie=\"%s\" -o \"%s\"",zip,
preloader, SWFDIR, preloader, outputname, outputname);
if(!system_quiet)
printf("\n");
if(preloader && viewer) {
systemf("swfcombine \"%s\" viewport=%s -o __tmp__.swf",
viewer, outputname, outputname);
- systemf("swfcombine `swfdump -XY \"%s\"` `swfdump -r \"%s\"` %s/PreLoaderTemplate.swf loader=%s movie=__tmp__.swf -o \"%s\"",
+ systemf("swfcombine %s `swfdump -XY \"%s\"` `swfdump -r \"%s\"` %s/PreLoaderTemplate.swf loader=%s movie=__tmp__.swf -o \"%s\"",zip,
outputname, preloader, SWFDIR, preloader, outputname);
systemf("rm __tmp__.swf");
}